API Connector Documentation
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
- Part 1: Get Notion Token
- Part 2: Allow Access for Your Token
- Part 3: Example API Requests
- Part 4: Handle Pagination
- Part 5: API Documentation
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
Part 1: Get Your Notion Token
- Log in to Notion and click Settings & Members on the left side navigation menu
- Click Connections and then Develop or manage integrations
- Click + New Integration
- You'll be prompted to give your integration a name and a logo. These can be anything, but remember what you pick :p. Click Submit.
- You will be presented with an internal token that you can use to make your API requests.
- Scroll to the bottom of the page, make sure Internal integration is selected, and click Save. Congrats, you have your token! Copy it down as we'll use it shortly.
Part 2: Allow Access for Your Token
By default, the token you've just created doesn't have access to your Notion data until you explicitly share access. To share access, you'll need to add it like this.
- Navigate to your page or database, and click the click the ••• button on top right.
- Scroll down to the bottom and click +Add connections
- In the resulting pop-up, search for and select the integration you created earlier.
- You'll see a message informing you that your integration will now have access to the page. Click Confirm.
Now your page is available via the API.
Part 3: Example API Requests
Notion provides the following endpoints. Note that some of these requests use GET
while others use POST
, as this will be important for pagination handling.
HTTP method | Endpoint |
---|---|
GET | List all users |
GET | Retrieve block children |
GET | Retrieve a comment |
GET | Retrieve a page property item |
POST | Query a database |
POST | Search |
Example - Query Records from a Notion Database
This example shows how to pull records from a Notion database into Sheets.
- First, get your Notion database ID. Get your Notion database ID from the URL (or see below for another method). If your URL is
https://notion.so/xxxx?v=YYYYY
,xxxx
is your database ID. - Open up Google Sheets and click Extensions > API Connector > Open > Create request.
- In the request form, enter the following, substituting in your own database ID and API key:
- Application:
Custom
- Method:
POST
- Request URL:
https://api.notion.com/v1/databases/your_database_id/query
- Headers
Authorization
:Bearer your_key
Notion-Version
:2022-06-28
Content-Type
:application/json
- Request body:
{}
- Application:
- Create a new tab and click Set current to use that tab as your data destination.
- Name your request and click Run. A moment later you'll see database records populate your sheet.
Example - Search Available Notion Pages and Databases
You can search all the databases you have access to with a request like this:
- Application:
Custom
- Method:
POST
- Request URL:
https://api.notion.com/v1/search
- Headers
Authorization
:Bearer
your_key
Notion-Version
:2022-06-28
Content-Type
:application/json
- Request body:
{"filter":{"value":"database","property":"object"}}
To see available pages, change database
to pages
in the request body. To see all available entities, enter {}
into the request body (but Notion recommends being as specific as possible).
More Example API URLs
For these, you'll need your page ID from the page URL
Substitute in that page ID where it says 11111111
- Get metadata about a page
GET
https://api.notion.com/v1/pages/11111111
- Get content from a page
GET
https://api.notion.com/v1/blocks/11111111/children
Part 4: Handle Pagination
By default, Notion API limits 100 responses per page as shown in their documentation:
To get more records, use the start_cursor
parameter as described. In API Connector you can do this automatically with pagination handling, like this.
- Pagination type:
cursor body
- Next token parameter:
start_cursor
- Next token path:
next_cursor
(this is the column name containing the tokens) - Run until: choose when to stop fetching data
POST
requests. If you're querying one of their GET endpoints, the pagination type will be cursor
instead. The next token parameter and path will remain the same either way.Part 5: API Documentation
Official API documentation: https://developers.notion.com/reference/intro
This does not work for me. I think the problem stems from my page ID. The page that contains the database has 2 ID numbers:
https://www.notion.so/workspace-name/%5B32 character string here]?v=[32 character string here]
Can you suggest a fix? Thanks!
The database URL should have 2 numbers; the first is the database ID and the second is the view ID. Can you try plugging in the first number and see if that resolves the issue? I just updated the article to include a more complete example of getting records from a database.