Automate Notion from your terminal with the Notion CLI
Use the Notion CLI to query databases, write pages from Markdown and deploy Workers that sync data into Notion, all from your terminal in under 35 minutes.

What you need
The Notion CLI is in beta. It runs in a desktop terminal and doesn't work on mobile.
Step 1: Install the Notion CLI
3 minThe CLI is called
ntn, and one install gives you API calls, page edits and Workers.- On macOS or Linux, open a terminal and run the install script below.
- On Windows x64, run
winget install Notion.ntninstead. With Node.js 22 or later,npm install --global ntnworks on any system. - Restart your terminal so it can find
ntn, then check the version.
Run thiscurl -fsSL https://ntn.dev | bash ntn --version
You should see a version number printed under the command.
The installer can't write to /usr/local/bin?
Run it again with a folder you own:
curl -fsSL https://ntn.dev | NTN_INSTALL_DIR="$HOME/.local/bin" bash. If that folder isn't on your PATH, the installer prints the line to add.To read the script before you run it, open ntn.dev/install.sh.
Step 2: Log in to your workspace
3 minLogging in links the CLI to one workspace and keeps your token in the system keychain.
- Run
ntn login. A browser window opens. - Check that the code in the browser matches the code in your terminal, then approve.
- Run
ntn doctorto check your login, keychain, network and config. - Run
ntn api v1/users/meto make your first API call.
Run thisntn login ntn doctor ntn api v1/users/me
You should see a JSON reply with your Notion user name and ID.
Login fails with a keychain error?
This happens in containers, CI runners and SSH sessions. Run
NOTION_KEYRING=0 ntn loginto keep the token in a file instead, and guard that file like a password.For scripts and CI, create a personal access token in the Developer portal and export it as
NOTION_API_TOKEN. Keep it out of code and shared files.- Run
Step 3: Query a database
5 minA Notion database holds one or more data sources, and you query the data source, not the database.
- In Notion, open the database's settings menu and choose Manage data sources.
- Click the data source's ••• menu, then Copy data source ID.
- Run the query below with your ID. Change
StatusandOpento a property and option from your own database. - Add
--jsonto the command when a script orjqneeds to read the output.
Run thisntn datasources query [DATA SOURCE ID] --limit 50 --filter '{"property":"Status","select":{"equals":"Open"}}'You should see up to 50 rows from your database where Status is Open.
The query fails on a property name?
Names must match the database exactly, capitals included. Run
ntn api v1/data_sources/[DATA SOURCE ID]to print the schema and copy the names from it.Only have a database ID? Run
ntn datasources resolve [DATABASE ID]to list its data source IDs.Step 4: Write pages from Markdown
4 minWriting pages as Markdown lets a script post notes, logs or reports into Notion without building API JSON.
- Find the page to write under:
ntn api v1/search query="[PAGE TITLE]", and copy itsid. - Save your notes in a file called
notes.md. - Create a child page from the file with
ntn pages create. - Read any page back as Markdown with
ntn pages get.
Run thisntn api v1/search query="[PAGE TITLE]" ntn pages create --parent page:[PAGE ID] < notes.md ntn pages get [NEW PAGE ID]
You should see a new page under your parent page, with the headings and lists from notes.md.
An edit won't remove a child page?
ntn pages editprotects child pages and databases by default. Add--allow-deleting-contentonly when you really mean to delete them.The CLI can only read and change pages your Notion account can open.
- Find the page to write under:
Step 5: Deploy your first Worker
10 minA Worker is a small TypeScript program that Notion hosts and runs, so nothing has to stay running on your laptop.
- Run
ntn workers new my-worker, thencd my-worker. - Open
src/index.ts. It holds a sample tool calledsayHello. - Run
ntn workers deployand follow the prompts. - Run the sample tool from the same folder to test it.
Run thisntn workers new my-worker cd my-worker ntn workers deploy ntn workers exec sayHello -d '{"name": "World"}'You should see the reply
Hello, World!in your terminal.Workers commands fail with a plan or access error?
Workers need a Business or Enterprise plan. They're on for owners by default, and admins choose who else can use them, so ask an admin to add you.
Workers are free to try during the beta. Notion says they will later use Notion credits, at about $0.0023 a run.
- Run
Step 6: Add a scheduled sync or a webhook
8 minA sync pulls outside data into a Notion database on a schedule, and a webhook runs your code when another service sends an event.
- Store the outside service's API key as a Worker secret with
ntn workers env set. - Add a sync to
src/index.tswith a schedule such as"1h". The template ships with a/syncskill your coding agent can use. - Redeploy, then test with
--preview, which runs the sync without writing to Notion. - For a webhook, run
ntn workers webhooks listand paste the URL into the other service.
Run thisntn workers env set GITHUB_TOKEN=[YOUR TOKEN] ntn workers deploy ntn workers sync trigger [SYNC KEY] --preview ntn workers sync status
You should see a live status view for your sync, updated every 2 seconds.
Runs fail with a rate limit error?
Each workspace gets 600 sync runs an hour across all Workers. Use a longer schedule, such as
"1h"or"1d", for data that changes slowly.Treat secrets and webhook URLs like passwords. Anyone with a webhook's full URL can send it events, so keep both out of code and shared files.
- Store the outside service's API key as a Worker secret with
You get
A terminal setup that reads and writes Notion, plus a Worker that keeps a database in sync on its own
Try next
Did this guide work for you?
Thanks. It helps us fix the steps.


