Using the new Notion API to create my custom Warzone stats tracker

Mart Noten
4 min readMay 17, 2021

During these COVID-19 days i’m spending more time with my friends in Verdansk then in the pub. The fights over who’s going to get the next round have evolved to who got the most headshots in the match and like with anything, data is king. There are great websites available to help you win your arguments and wzstats.gg is one of them. With the newly published Notion API BETA i’m looking to get ahead of the arguments by creating my own custom database of Warzone statistics, to see how i’m actually doing.

At the end of this post

I’ll have walked you through the required steps to build your own custom integration with Notion and how you can use it to build your own Warzone tracker. Or something like that, maybe something more useful. In the next post in this series we will populate the Notion page automatically by using AWS Lambda to fetch the latest daily matches and put them into Notion.

If you’re interested in looking ahead on how to automate the retrieval using Serverless technologies, take a look at our NBTL blog that contains posts like:

Requirements

Notion has published great documentation with the API, so I won’t copy-paste everything from there. You can find the full documentation and list of requirements here, but it’s all pretty straight forward.

Photo by Amr Taha™ on Unsplash

Step 1: Create a new Notion integration

Open up your integrations in Notion and create a new Integration. Give the integration a name, get yourself a fancy icon from FlatIcon.com, and associate it with a workspace.

Find the Internal Integration Token under Secrets. Show and copy the token. Paste it somewhere you can easily find later, like in your text editor.

Step 2: Create a new Notion page in Notion to which you want to grant access

You need to specifically grant permissions to every page and/or database you want to access with your integration. This way, you can keep information secure in your workspaces. In my case, I’m creating a page specifically for my new integration and sharing it with my bot. To do so, click on Share and Add people. You should then see your integration appear in the list.

The last thing we’re going to need to do is fetch the ID of the database you just created. Note that this is different from the ID of the page. With the instructions below, make sure that you click on the Share button of the database/table, and not the page itself.

  • If you’re using the Notion desktop app, click on the Share button once again and select Copy link. Paste and navigate to this URL in your browser. You may need to log into the Notion workspace if you haven’t already. Follow the instructions for the browser in the next bullet.
  • If you’re using Notion in a browser and viewing the database as a full page, the database ID is the part of the URL after your workspace name and the slash (acme/) and before the question mark (?). The ID is 32 characters long, containing numbers and letters. Copy the ID and paste it somewhere you can easily find later.

Step 3: Test the connection using Postman

Now that everything is set up we only need to test that our Integration is able to successfully create new items in our page. You should be able to do so per cURL request as in the Notion documentation or by using an API client like Postman. You can find an example of how to import a cURL into a Postman request here. Or use the example cURL command, found below, from the documentation. Once successfully executed, you should see your new item in Notion appear!

curl -X POST https://api.notion.com/v1/pages \   
-H "Authorization: Bearer {MY_NOTION_TOKEN}" \
-H "Content-Type: application/json" \
-H "Notion-Version: 2021-05-13" \
--data '{ "parent": { "database_id": "{DATABASE_ID}" }, "properties": { "Name": { "title": [ { "text": { "content": "Yurts in Big Sur, California" } } ] } } }'

Conclusion

Now that you have successfully set up the required Notion integration, you can start thinking on how to automate the logic behind fetching your latest statistics. In the next post in this series we will build out an AWS Lambda function that is executed every hour to fetch my latest playing statistics and update them in my Notion database.

This post is a part of the NBTL blog that contains real-life examples of building on the cloud. Give us a visit if you're interested in learning more about software development on cloud services.

--

--

Mart Noten

AWS Architect from the https://nbtl.substack.com/ writing technical articles focussing on cloud technologies.