Search API Connector Documentation

Print

Import Notion Data to Google Sheets

In this guide, we’ll walk through how to pull data from the Notion API directly into Google Sheets, using the API Connector add-on for Sheets. We’ll first get an API key from Notion, and then set up a request to pull in data to your spreadsheet.

CONTENTS

BEFORE YOU BEGIN

Click here to install the API Connector add-on from the Google Marketplace.

PART 1: CREATE YOUR NOTION ACCOUNT

Before start using the Notion API & services, you will need a registered account. Navigate yourself to this page and enter your email address.

If you don’t have an account, you will receive a temporary code to your email address. Use that code and enter it into the second textbox that appeared in the meantime.

After that, you will be redirected to the register page. Enter your data.

Choose your account plan!

Now when you have an account, we can experiment with Notion API and services!

PART 2: CREATE YOUR API REQUEST URL

We will create Notion API requests based on the official documentation.

  • API root: https://api.notion.com/v1/
  • Endpoints:
    • databases
    • pages
    • blocks
    • users
    • search

PART 3: USE NOTION API DATA WITH GOOGLE SHEETS

In this section, we will show you how to use an API link to push your data into the notion databases. Throughout this example, we will create a vacation planner and push a destination to our vacation table created in the Notion workspace. We will use the pages endpoint!

Before we start, we need to create a Notion’s workspace. Navigate yourself to your account page and follow the instructions depicted in the picture below.

To explore more about how to work with workspaces, we highly encourage you to go through this documentation page!

Now when we created a workspace, we need to create a new integration! Open your integrations page and click on the button New integration.

Name your integration, choose a logo picture, and associated workspace (you can choose the one we previously created). As this example is about planning a vacation destination, I named it Vacation planner.

Submit to create an integration and get an internal integration token that you will need to push or pull your data associated with this integration!

As integrations don’t have access to any pages or databases, we must share specific pages/databases with the integration to provide accessibility for those pages using the APIs. Go to your workspace’s page and create a database by typing /table. Select a full page table, give it a title (I named main Vacation destination planner).

Now, we need to connect it with the created integration. Click on the Share button in the upper right corner, and after that on Add people, emails, groups, or integrations textbox.

In the pop-up will appear previously created integration! Select it and click on Invite.

Now when we connected our workspace with our integration, we gave it permission to read, write and edit the new database! Before we proceed with using the API link, we need the ID of our database. In the browser, the database’s ID is a part of the URL page. It’s located between the slash (/) and question mark (?) and it’s 32 characters long. Copy the ID, you will need it later!

Please note: If you are using the Notion desktop application, you should click on the Share button once again and select the copy link to obtain the database’s ID.

Now when we set up everything, let’s use API-Connector to push some data!

  1. Open up Google Sheets and click Add-ons > API Connector > Open.
  2. In the Create tab set method to POST and enter the link:
https://api.notion.com/v1/pages

Fill the headers in the following way:

  • Authorization – Bearer MY_NOTION_TOKEN
  • Content-Type – application/json
  • Notion-Version – 2021-05-13

3. Fill the POST body with the following JSON (please note: this is an example, feel free to modify it according to your needs):

{
    "parent": { "database_id": "DATABASE_ID" },
    "properties": {
      "Name": {
        "title": [
          {
            "text": {
              "content": "Yurts in Big Sur, California"
            }
          }
        ]
      }
    }
  }

4. Now create a new tab, give it a name and click Set current to use that tab as your data destination.

5. Give a name to your request and click run!

6. Now the pushed data will appear into the Vacation destination planner (or however you named it)!

7. If you want to list all your created databases into google sheets, change the method from POST to GET, and enter the following API link:

https://api.notion.com/v1/databases/

Everything else is the same: set your destination sheet, save it and run it!

PART 4: MORE EXAMPLE API URLS

Here we will present more API URL examples. We encourage you to go through the Notion API documentation for constructing even more examples! The procedure for working with other endpoints is the same as in the example above. Depending on what are you doing, you should use one of the endpoints (pages, databases, etc.) and its associated parameters.

  • To create a page:
POST https://api.notion.com/v1/pages

Headers:

  • Authorization – Bearer {MY_NOTION_TOKEN}
  • Content-Type – application/json
  • Notion-Version – 2021-05-13

JSON Post body:

{
      "parent": { "type": "database_id", "database_id": "DATABASE-ID" },
      "properties": {
      "Grocery item": {
        "type": "title",
        "title": [{ "type": "text", "text": { "content": "Tomatoes" } }]
      },
      "Price": {
        "type": "number",
        "number": 1.49
      },
      "Last ordered": {
        "type": "date",
        "date": { "start": "2021-05-11" }
      }
    }
  }
  • To find a page in the database by specific condition (e.g. groceries (from the example above) ordered past week)
POST https://api.notion.com/v1/databases/DATABASE-ID/query 

Headers:

  • Authorization – Bearer {MY_NOTION_TOKEN}
  • Content-Type – application/json

JSON Post body:

{
      "filter": {
      "property": "Last ordered",
      "date": {
        "past_week": {}
      }
        }
    }

PART 5: PAGINATION

Notion API limits 100 responses per page. Pagination can be handled using the Cursor-Based Pagination (for more information, please refer here) with the parameters:

  • start_cursor = A cursor returned from a previous response, used to request the next page of the result. The default value is undefined, which means it will return results from the beginning of the list.
  • offset = max records to return, default and the maximum value is 100

As the Cursor-Based pagination provides in a response a token that is being used for running subsequent requests, you will need to run the request first in order to obtain the token column. To retrieve page one, run the following request:

GET https://api.notion.com/v1/databases

This request will return the next_cursor column which you should use to run the request for the following page:

GET https://api.notion.com/v1/databases?start_cursor=MTY3NDE4NGYtZTdiYy00NzFlLWE0NjctODcxOTIyYWU3ZmM3

Automatic pagination handling

Pagination can be handled automatically with the pagination handling feature, like this:

  • API Request URLenter your request URL as usual, e.g. 
GET https://api.notion.com/v1/databases

Set the API-Connector’s pagination options in the following way:

  • Pagination type: cursor
  • Next token parameter: start_cursor
  • Next token field: next_cursor (column name where the tokens are)
  • Number of pages: 15
Previous Import Netflix Data from RapidAPI to Google Sheets
Next Import Okta Data to Google Sheets

Leave a Comment

Table of Contents