How to test the Notion API

The Notion API is popular for internal tools: push a deploy log into a database, turn form submissions into pages, build a dashboard from a team wiki. Its quirks are easy to trip over without seeing the raw requests: a required version header, pages that must be shared with your integration before it can see them, and rich text that's a list of objects, not a string.

Step 1: Integration and environment

At notion.so/my-integrations, create an internal integration for your workspace and copy its secret.

VariableValue
baseUrlhttps://api.notion.com/v1
notionTokenthe integration secret, marked as secret
notionVersionthe API version from Notion's docs, such as 2022-06-28
pageIda test page the integration can see

On the collection's Authorization tab, choose Bearer token with {{notionToken}}, and set the version header once in the collection's pre-request script:

JavaScript
pm.request.headers.set('Notion-Version', pm.environment.get('notionVersion'));

Step 2: Share a page with the integration

This is the step everyone misses. An integration sees nothing until a page is shared with it. Open the test page in Notion, use the ••• menu → Connections, and add your integration. Child pages inherit access.

Then check:

HTTP
GET {{baseUrl}}/pages/{{pageId}}
JavaScript
pm.test('integration can read the page', () => pm.response.to.have.status(200));

A 404 with object_not_found usually means "not shared with this integration", not "doesn't exist".

Step 3: Read a page's content

A page's content is its child blocks:

HTTP
GET {{baseUrl}}/blocks/{{pageId}}/children?page_size=50
JavaScript
const body = pm.response.json();
pm.test('returns blocks', () => pm.expect(body.results).to.be.an('array'));
pm.environment.set('cursor', body.has_more ? body.next_cursor : '');

Lists in the Notion API page with has_more and next_cursor. Pass the cursor as start_cursor to get the next page. See How to test API pagination.

Step 4: Create a page

Text in Notion is always an array of rich-text objects:

HTTP
POST {{baseUrl}}/pages
Content-Type: application/json

{
  "parent": {"page_id": "{{pageId}}"},
  "properties": {
    "title": {"title": [{"text": {"content": "API test {{$isoTimestamp}}"}}]}
  },
  "children": [
    {
      "object": "block",
      "type": "paragraph",
      "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Created by an API test. Safe to delete."}}]}
    }
  ]
}
JavaScript
pm.test('page created', () => pm.response.to.have.status(200));
pm.environment.set('newPageId', pm.response.json().id);

Clean up by archiving it:

HTTP
PATCH {{baseUrl}}/pages/{{newPageId}}
Content-Type: application/json

{"archived": true}

Step 5: Databases

Pages in a database have typed properties (select, date, number…), and each type has its own JSON shape. The quickest way to get them right is to read an existing entry first, then copy the shape of its properties into your create request. Database endpoints have been changing between Notion API versions, so check the reference for the version you've set before you rely on a request from an older example.

Errors to know

StatuscodeUsual cause
400missing_versionNo Notion-Version header
400validation_errorWrong JSON shape; the message names the path
401unauthorizedWrong token
404object_not_foundNot shared with the integration, or a wrong ID
429rate_limitedAbout 3 requests a second on average; wait for Retry-After

The rate limit is low, so add a delay to collection runs:

Terminal
requestarium run-collection "Notion" --env Notion --delay 400 --env-var notionToken=NOTION_TOKEN