IntegrationsIntermediate

How to Create a Notion Internal Integration Token for AI Scripts

Generate a Notion API token and share a database with it so your own AI scripts can read and write Notion programmatically.

9 minIntermediate

If you are building your own AI workflow, you need a Notion integration token rather than a chat connector. The token lets a script authenticate to the Notion API and read or update a database directly. This guide walks through creating the integration, sharing a database with it, and making your first authenticated call.

  • A Notion account that can create integrations
  • A database you want to read or write
  • curl or Node installed for the test call
  • About 12 minutes

Step 1: Create the integration

Go to notion.so/my-integrations and click New integration. Give it a name, pick the workspace, and choose the capabilities it needs. Read content is enough for analysis; add Insert and Update content if your script will write back.

Notion - My integrations - New integration
New integration
----------------------------------
Name: AI Reporter
Workspace: Acme Inc
Capabilities:
[x] Read content
[x] Update content
[ ] Insert content
[ Submit ]
Name the integration and set its capabilities.

Step 2: Copy the secret token

After submitting you land on the integration page. Copy the Internal Integration Secret. It starts with ntn_ and acts like a password, so store it in a secrets manager or an environment variable, never in committed code.

.env
NOTION_TOKEN=ntn_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
NOTION_DATABASE_ID=replace_with_your_database_id

Step 3: Share the database with the integration

An integration sees nothing until you explicitly share content with it. Open the target database, click the three-dot menu, choose Connections, and add your integration by name. The database id is the 32-character string in the database URL.

Notion - Database - Connections
Tasks (database) ... -> Connections
----------------------------------
Search: AI Reporter
+ AI Reporter [ Confirm ]
Connected:
- AI Reporter (can edit)
Add the integration so it gains access to this database.

Step 4: Make a test query

Call the query endpoint for your database. A 200 response with a results array means the token and the share both worked. The Notion-Version header is required; use the current dated value.

zsh - notion-test
$curl -X POST "https://api.notion.com/v1/databases/$NOTION_DATABASE_ID/query" \
$ -H "Authorization: Bearer $NOTION_TOKEN" \
$ -H "Notion-Version: 2022-06-28" \
$ -H "Content-Type: application/json"
{ "object": "list", "results": [ { "id": "..." } ] }
$
object_not_found means it is not shared
If the API returns object_not_found, the token is valid but the integration was never added to that database. Repeat Step 3 on the exact database you are querying.

Example: feed the results array into your AI script and ask it to triage tasks or write a daily summary back into a page. The same token now powers any read or write your capabilities allow.

Watch related tutorials

Tags
#notion#api#token#automation