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 data source

Pass the data source ID to Query a data source.

Retrieve a page

Create a page

Update page properties

Read page content (blocks)

Create a meeting note for a calendar event

A worker with a connected calendar can create a full-page meeting note and link it to an event. The worker must pass parent, which should be a meetings database shared with the worker. To find an event’s IDs, see Link a full-page meeting note to a calendar event. This works with the token Notion provides to the worker, or with a personal access token. An internal connection API token returns a 403.
If the event already has other meeting notes, the link request returns a 409. Delete the meeting note you created, or pass allow_other_meeting_notes: true to link anyway.

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 connection API token: the client can only access pages and databases explicitly shared with the connection.
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.