Skip to main content
Every capability’s execute function receives a Notion API client as context.notion. This is the official @notionhq/client SDK (the same one you’d use outside of Workers):

Authentication

How the client is authenticated depends on how the capability runs: To set a token for syncs, webhooks, or local development, you have two options:
1

Create a token

Create a personal access token or an internal integration and copy the token.
2

Store the token as a secret

3

Grant access (internal integrations only)

If using an internal integration, open each page or database your worker needs to access, select the ••• menu in the top right, and add the integration under Connections. Personal access tokens don’t need this step.
For local development, pull secrets to a .env file so the token is available when running ntn workers exec:

Common operations

The examples below use { notion } destructured from the second argument to execute. They work the same way in tools, syncs, and webhooks:

Query a database

Retrieve a page

Create a page

Update page properties

Read page content (blocks)

Permissions

What the client can access depends on the token type:
  • Custom Agent tools: the client has the same permissions as the Custom Agent.
  • Personal access token: the client uses your Notion permissions and the token’s capabilities.
  • Internal integration token: the client can only access pages and databases that the integration has been explicitly connected to via the Connections menu.
If a request returns a 403 or 404, check that your token has access to the relevant page. For full SDK documentation, see the Notion API reference and the TypeScript SDK on GitHub.

Next steps

Syncs

Sync external data into Notion databases.

Agent tools

Build custom tools for Notion AI.

Webhooks

Receive HTTP events from external services.

OAuth

Connect to third-party APIs with user authorization.

Secrets

Store API keys and credentials securely.