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:
- Personal access token: acts as you and uses your page permissions. You don’t need to connect it to each page.
- Internal integration token: acts as a bot, with access limited to pages explicitly connected via the Connections menu.
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.
.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
Search
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.
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.