My journey

By trace

Integrating Notion with Outerbase

 ·

4 min read

Cover Image for Integrating Notion with Outerbase

NOTE: Outerbase is in beta, so things are subject to change. This article will explain how I created a command to integrate Notion with Outerbase. I created a command that fetches information from Notion and then called that command in my next.js application to display the information from Notion.

Outerbase: Outerbase is a modern, cloud-based database interface that enhances teamwork and efficiency. It features EZQL, a natural language to SQL agent for easy data queries, and allows real-time collaboration, workflow automation, and data visualization. It's suitable for developers for simplified database management, product teams for direct data access, and businesses for a comprehensive database view and cost reduction.

Notion: Notion is a versatile and popular productivity and collaboration software platform that provides tools for note-taking, project management, database management, document creation, and more. It allows users to create and organize various types of content in a flexible and interconnected manner. Notion is designed to be customizable, making it suitable for a wide range of personal and professional use cases.

Pre-requirement

  1. Next.js application

  2. A Database in Notion

What will I not cover in this article?

  1. How to set the basic next.js installation. For that, check the next.js documentation

  2. How to create a database in Notion. They have a great guide on their official site, so you can check that one out here. If you have never created one before and are very new to this space, I would recommend you click on this link and then duplicate it by clicking on the "Duplicate" button on the top right corner.

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694774697516/12f1a836-eb24-4195-a02f-951623038e52.png align="center")

What will I cover in this article?

Going forward, I will assume that you made a "Duplicate" of my database.

  1. Getting your database id

  2. Creating an integration in Notion.

  3. Connecting the Notion database with the created Notion integration.

  4. Creating a Command in Outerbase to integrate the Notion API.

Fetching data with the help of the created Command and then displaying that data in the front end.

Getting the database ID

  1. Once you have made a duplicate of my database from the link I have shared. You should see something similar to this.

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694775303132/16c1ef69-e104-453a-8679-5d8ccf903c4d.png align="center")

    1. The link that gets generated should be something similar to this
      'https://www.notion.so/0ad335653a7b4979ac69a49b60f20725?v=9a9815126f194d79884d26ad93bc4480'

    2. Your database id is the number after '/' after 'so' until '?', so in this case, it is "0ad335653a7b4979ac69a49b60f20725". It always has 32 characters.

Creating an integration in Notion

I am assuming you have the database set up.

  1. Go to https://www.notion.so/my-integrations

  2. Click on "+ New Integration"

  3. Name it to your liking I named it "outerbase-integration" and then click on "Submit"

  4. Now you should see your Secret Key. Keep it safe somewhere; we will use it while creating the command.

The database id and the secret key are all you need to integrate the Notion Public API with the Outerbase command.

Connecting the Notion database with the created Notion integration

Now we need to connect the database with the notion integration. This step is really important.

  1. Click on the '...' button on the top right corner of your database, and a drop-down menu will appear. Click on 'Add Connections' and find the same integration you just created for me; it is called 'outerbase-integration'.

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694776143611/b1fd1439-78e6-48fa-816b-a2d7175fa347.png align="center")

    1. Verification: To check that the integration has successfully connected with the database. Run this curl command with your database id and secret key
curl 'https://api.notion.com/v1/databases/DATABASE_ID' \
  -H 'Authorization: Bearer YOUR_NOTION_SECRET' \
  -H 'Notion-Version: 2022-06-28'

For successful integration, you should see something similar to this:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694776664164/f7f1b5ee-5309-44d9-b5e6-475bd1d91e0f.png align="center")

Creating a Command in Outerbase to integrate the Notion API

  1. Click on the "+ New Icon" and click on "Commands"

  2. A form will appear. Fill in the values with your desired name and Choose Post.

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694619657024/47e5d202-d2af-4860-8be5-58cdc1f985ba.png?auto=compress,format&format=webp align="left")

  3. Click on "+" below the box and Click on "Javascript"

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694777565178/84e8c9a5-f166-43ec-a81a-715659bd0893.png align="center")

  4. Paste the following code:

    async function userCode() {
          const response = await fetch(`https://api.notion.com/v1/databases/YOUR_DATABASE_ID/query`, {
          method:"POST",
          headers: {
            'Authorization': 'Bearer YOUR_API_SECRET',
            'Content-Type': 'application/json',
            'Notion-Version': '2022-06-28'
          },
        });
        const data = response.json()
      return data;
    }
    

    That's it. You have successfully created a Command in Outerbase to integrate Notion.

Communicating with Front-end with the created command

  1. Feel free to check out the whole code here. In this article, I will only go through the communication part.

  2. In my code you will notice this part

 const database = await fetch(
    `https://daily-beige.cmd.outerbase.io/getDatabase`,
    {
      method: "POST",
      headers: {
        "content-type": "application/json",
      },
      cache: "no-cache",
    }
  );
  const data = await database.json();
  const { results } = data;

This is how I am calling the Outerbase command to fetch the information.

Then I created a simple table to display the content. Which can be seen here.

Github Repo: https://github.com/trace2798/outerbase-command-notion

I hope this article helps you. If you have any questions, feel free to leave a comment, and I will respond to them as soon as possible.

Happy Hacking !!!

Comments (1)

Discuss on Hashnode

Wow, you kept the article simple, making it easy to follow. Your guide sends notion data to our frontend app, cool. Does Notion allow developers to send data to it from the front-end? Like creating a to-do list on our app and having it also send that data to Notion.