Getting data from a Notion table
In this tutorial, we'll show you how to use Notion as a backend with Bravo. We'll connect these two Notion tables to Bravo. The tables contain a list of videos and a list of podcasts from TED.
In order to follow the tutorial, access the Notion page below and duplicate it to your own Notion workspace.
First of all, we need to add an integration to our Notion workspace. This will provide us an API key, which we can use to access the content we want to expose via API. This is done by following the first two steps indicated here. When creating the integration, select
Internal Integrationas shown below.
You should copy the
Internal Integration Tokenand keep it somewhere safe.
After creating the integration, you need to give it access to our two tables. On our Notion page, we have two tables: one with a list of videos, and another one with a list of podcasts. For each of the tables, click on
Open as page, and then share the page with the integration, as shown in step 2 here. Share the main page containing the two tables with the integration as well.
Now the two Notion tables are accessible via API! Let's jump into Bravo Studio and set up the requests in the Data Library.
After configuring Notion to allow for API calls targeting our tables, let's create requests in the Data Library.
Before creating the requests, we need to get the
Database IDof the two tables we have. That's the string indicated below.
After copying those values, go to the Data Library in Bravo Studio, and create a new Data Collection. All the requests in the collection need to be authenticated. For that, you need to include the following header in all the requests, replacing API_KEY in the screenshot for the
Internal Integration Tokenof your Notion integration.
Notion API offers two possibilities to obtain the table data:
- The Retrieve option is performed via a
GETrequest and returns all the data stored in the table.
- The Query option also returns the table data, but allows for sorting and filtering. It's performed via a
POSTrequest, as additional information needs to be sent in the request body. Feel free to explore all the options available in the Notion API reference.
We'll now get the data in the
Podcaststable via a
Retrieverequest. In order to do that, create a new
GETrequest and use the following URL, with the
Database IDfor that table.
That request will return all the table data, together with all its properties. The data will come as a list of items, one item per table record.
Now, we'll create a Query request for the Talks table. It will be a
POSTrequest. In this case, we want to get all the records of that table, sorted by the Importance field.
We'll use the following URL and JSON body:
As you can see below, we'll get all the data in the Talks table, sorted by importance.
Happy bravorizing! 🎉