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.
| Variable | Value |
|---|---|
baseUrl | https://api.notion.com/v1 |
notionToken | the integration secret, marked as secret |
notionVersion | the API version from Notion's docs, such as 2022-06-28 |
pageId | a 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:
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:
GET {{baseUrl}}/pages/{{pageId}}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:
GET {{baseUrl}}/blocks/{{pageId}}/children?page_size=50const 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:
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."}}]}
}
]
}pm.test('page created', () => pm.response.to.have.status(200));
pm.environment.set('newPageId', pm.response.json().id);Clean up by archiving it:
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
| Status | code | Usual cause |
|---|---|---|
400 | missing_version | No Notion-Version header |
400 | validation_error | Wrong JSON shape; the message names the path |
401 | unauthorized | Wrong token |
404 | object_not_found | Not shared with the integration, or a wrong ID |
429 | rate_limited | About 3 requests a second on average; wait for Retry-After |
The rate limit is low, so add a delay to collection runs:
requestarium run-collection "Notion" --env Notion --delay 400 --env-var notionToken=NOTION_TOKEN