notion-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Notion CLI

Notion CLI

Look things up before answering

作答前先查询相关信息

The CLI is self-documenting. Always prefer running these commands over guessing syntax or relying on memorized knowledge:
  • ntn api ls
    — list every public API endpoint.
  • ntn api <path> --help
    — show methods, doc links, and usage for an endpoint.
  • ntn api <path> --docs
    — print the full official docs for an endpoint.
  • ntn api <path> --spec
    — print a reduced OpenAPI fragment (useful for understanding request/response schemas).
  • ntn <command> --help
    — help for any command or subcommand.
该CLI具备自文档功能。请始终优先运行以下命令,而非猜测语法或依赖记忆的知识:
  • ntn api ls
    — 列出所有公开的API端点。
  • ntn api <path> --help
    — 显示某个端点的可用方法、文档链接及使用方式。
  • ntn api <path> --docs
    — 打印该端点的完整官方文档。
  • ntn api <path> --spec
    — 打印简化版OpenAPI片段(有助于理解请求/响应 schema)。
  • ntn <command> --help
    — 获取任意命令或子命令的帮助信息。

Install

安装

bash
npm i -g ntn@latest
bash
npm i -g ntn@latest

Authentication

认证

  • NOTION_API_TOKEN
    — required for
    ntn api
    and
    ntn files
    . Set this env var to a Notion integration token.
  • ntn login
    /
    ntn logout
    — session auth for
    ntn workers
    and
    ntn tokens
    . This does not authenticate
    ntn api
    or
    ntn files
    today.
  • NOTION_API_TOKEN
    — 使用
    ntn api
    ntn files
    时必填。请将此环境变量设置为Notion集成令牌。
  • ntn login
    /
    ntn logout
    — 针对
    ntn workers
    ntn tokens
    的会话认证。目前该认证方式不支持
    ntn api
    ntn files

ntn api

ntn api

Run
ntn api --help
for full syntax. Quick summary:
bash
undefined
运行
ntn api --help
查看完整语法。快速摘要:
bash
undefined

GET with query param

带查询参数的GET请求

ntn api v1/users page_size==100
ntn api v1/users page_size==100

POST with inline body fields

带内联请求体字段的POST请求

ntn api v1/pages parent[page_id]=abc123
ntn api v1/pages parent[page_id]=abc123

POST with JSON body

带JSON请求体的POST请求

ntn api v1/pages -d '{"parent":{"page_id":"abc123"}}'

The method is inferred (GET by default, POST when a body is present). Override
with `-X METHOD`.
ntn api v1/pages -d '{"parent":{"page_id":"abc123"}}'

请求方法会自动推断(默认GET,当存在请求体时为POST)。可通过`-X METHOD`手动指定方法。

ntn files

ntn files

Convenience wrapper around the File Uploads API.
bash
ntn files create < image.png
ntn files create --external-url https://example.com/photo.png
ntn files list
ntn files get <upload-id>
文件上传API的便捷封装。
bash
ntn files create < image.png
ntn files create --external-url https://example.com/photo.png
ntn files list
ntn files get <upload-id>

ntn workers

ntn workers

Manage Notion workers (deploy, list, execute, etc.). Run
ntn workers --help
for subcommands.
bash
ntn workers new my-worker        # scaffold a new project
ntn workers deploy               # deploy from current directory
ntn workers ls                   # list workers
ntn workers exec <capability>    # execute a capability
管理Notion workers(部署、列出、执行等)。运行
ntn workers --help
查看子命令。
bash
ntn workers new my-worker        # 快速搭建新项目脚手架
ntn workers deploy               # 从当前目录部署
ntn workers ls                   # 列出所有workers
ntn workers exec <capability>    # 执行某一功能

ntn tokens

ntn tokens

Manage tokens used by
ntn workers
. Requires
ntn login
. These are separate from
NOTION_API_TOKEN
integration tokens.
bash
ntn tokens create
ntn tokens ls
ntn tokens revoke <token-id>
管理
ntn workers
使用的令牌。需要先执行
ntn login
。这些令牌与
NOTION_API_TOKEN
集成令牌相互独立。
bash
ntn tokens create
ntn tokens ls
ntn tokens revoke <token-id>