Getting started with the Notion API

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Thanks Chris Bongers. Good job on the article! Your explanation was excellent, thank you! Saving it for later 👏
Glad you like it Savio! The Notion API is super cool to play around with, and I'm sure we can make cool projects with it
It is actually so easy, compared to some other API's However the details on creating/updating get a bit more complicated, watch our for the upcoming articles this week 👀
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

This article will explore the Notion API, mainly getting an API key and query a database.
For this article, we shall work with a request testing tool.
Notion is a component-based note-taking app. It offers databases, calendars, files, and much more.
I use Notion as the primary source for my blog articles, meaning this is where I keep track of what articles I'm writing and what status they have.
You can read more on my writing process here
You might be wondering, ok, but why do we need an API connection? Let's go back to what Notion offers us, and that included databases, right?
Meaning Notion can be a super easy database source for any application we wish to make.
Before we get started, you must be an admin of a workspace or create a new workspace yourself.
Once you established that, head over to https://www.notion.com/my-integrations and click the "+ New integration" button.

Give this new integration a name. As you can see above, I called one "API". Also, select the workspace it's associated too.
On the last screen, you will get an "Internal Integration Token" this is what we will be using to query our Notion database. So copy this to a safe location for now.

By default, our databases won't be available for this integration. We have to give access to it explicitly.
This will make the current page available for our integration. The next thing we need is the ID of this database.
Press the three dots on your table and click the "Copy link" button.

This will give you a URL that will look similar to this:
https://www.notion.so/6d6703dae1864e8ba381a9430447fc29?v=6b4520e686ef4b88a5f16b0ee54ffd5d
We need the part before the ? so in our case: 6d6703dae1864e8ba381a9430447fc29.
By now, we have everything that we need to test out the Notion API.
Head over to your favorite API Client.
First, let's query the database and get the structure of our table.
As the URL, use the following setup:
https://api.notion.com/v1/databases/6d6703dae1864e8ba381a9430447fc29
Where you will need to change the ID to the table ID we just got.
Then head over to the Auth section and choose to use a Bearer Token.

Then there is one last thing we need to add, and that is a Notion-Version header. Head over to the header section of your API client and add one like this:
Notion-Version: 2021-05-13

Now hit the send button and see what we'll get in return.

As you can see, this includes a database object and the fields that belong to it under the properties section.
In our case, there are two so far beings:
Of course, we also want to query for the actual data.
For that, we need to make a POST request to the same URL, but append /query at the end like this:
https://api.notion.com/v1/databases/6d6703dae1864e8ba381a9430447fc29/query

Here you can see we get multiple results, each containing numerous properties. In the screenshot, you can see one of these properties having the same set of properties.
And that's as far as we go today. We can create a new Notion integration and query a database table in Notion.
We'll go on and create a real-world example in another article.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter