Getting data from a Notion table
Last updated
Last updated
Notion is a powerful tool to store content, and it has recently released its beta API access.
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 Integration
as shown below.
You should copy the Internal Integration Token
and 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 ID
of 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 Token
of your Notion integration.
The Notion API is versioned, so you need to add another header (shown below) indicating the version. You should check what the current version is here.
Notion API offers two possibilities to obtain the table data: Retrieve
and Query
.
The Retrieve option is performed via a GET
request 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 POST
request, 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 Podcasts
table via a Retrieve
request. In order to do that, create a new GET
request and use the following URL, with the Database ID
for 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 POST
request. 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.
Now, we have two requests to get the data stored in our tables. In case you want to explore all the options the Notion API offers, you can check out the API documentation here.
Now you have the Notion data in Bravo, you can continue with data binding and connect the data to your app UI.
Happy bravorizing! 🎉