notion
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNotion CLI
Notion CLI
A CLI to manage Notion from the command line, using Notion's remote MCP server.
这是一个通过Notion远程MCP server从命令行管理Notion的CLI工具。
Prerequisites
前置条件
The command must be available on PATH. To check:
notion-clibash
notion-cli --versionIf not installed:
bash
go install github.com/lox/notion-cli@latestnotion-clibash
notion-cli --version如果未安装,请执行:
bash
go install github.com/lox/notion-cli@latestAuthentication
身份验证
The CLI uses OAuth authentication. On first use, it opens a browser for authorization:
bash
notion-cli auth login # Authenticate with Notion
notion-cli auth status # Check authentication status
notion-cli auth logout # Clear credentialsFor CI/headless environments, set environment variable.
NOTION_ACCESS_TOKEN该CLI使用OAuth进行身份验证。首次使用时,会打开浏览器进行授权:
bash
notion-cli auth login # 登录Notion完成身份验证
notion-cli auth status # 查看身份验证状态
notion-cli auth logout # 清除凭证对于CI/无头环境,请设置环境变量。
NOTION_ACCESS_TOKENAvailable Commands
可用命令
notion-cli auth # Manage authentication
notion-cli page # Manage pages (list, view, create, upload, edit)
notion-cli db # Manage databases (list, query)
notion-cli search # Search the workspace
notion-cli comment # Manage comments (list, create)
notion-cli tools # List available MCP toolsnotion-cli auth # 管理身份验证
notion-cli page # 管理页面(列出、查看、创建、上传、编辑)
notion-cli db # 管理数据库(列出、查询)
notion-cli search # 搜索工作区
notion-cli comment # 管理评论(列出、创建)
notion-cli tools # 列出可用的MCP工具Common Operations
常用操作
Search
搜索
bash
notion-cli search "meeting notes" # Search workspace
notion-cli search "project" --limit 5 # Limit results
notion-cli search "query" --json # JSON outputbash
notion-cli search "meeting notes" # 搜索工作区
notion-cli search "project" --limit 5 # 限制结果数量
notion-cli search "query" --json # 以JSON格式输出Pages
页面
All page commands accept a URL, name, or ID to identify pages.
bash
undefined所有页面命令均接受URL、名称或ID来指定页面。
bash
undefinedList pages
列出页面
notion-cli page list
notion-cli page list --limit 10
notion-cli page list --json
notion-cli page list
notion-cli page list --limit 10
notion-cli page list --json
View a page (renders as markdown in terminal)
查看页面(在终端中以markdown格式渲染)
notion-cli page view <page>
notion-cli page view <page> --raw # Show raw Notion markup
notion-cli page view <page> --json # JSON output
notion-cli page view "Meeting Notes" # By name
notion-cli page view https://notion.so/... # By URL
notion-cli page view <page>
notion-cli page view <page> --raw # 显示原始Notion标记语言
notion-cli page view <page> --json # 以JSON格式输出
notion-cli page view "Meeting Notes" # 通过名称查看
notion-cli page view https://notion.so/... # 通过URL查看
Create a page
创建页面
notion-cli page create --title "New Page"
notion-cli page create --title "Doc" --content "# Heading\n\nContent here"
notion-cli page create --title "Child" --parent "Engineering" # Parent by name
notion-cli page create --title "Child" --parent <page-id> # Parent by ID
notion-cli page create --title "New Page"
notion-cli page create --title "Doc" --content "# 标题\n\n内容在此处"
notion-cli page create --title "Child" --parent "Engineering" # 通过名称指定父页面
notion-cli page create --title "Child" --parent <page-id> # 通过ID指定父页面
Upload a markdown file as a page
将markdown文件上传为页面
notion-cli page upload ./document.md
notion-cli page upload ./doc.md --title "Custom Title"
notion-cli page upload ./doc.md --parent "Parent Page Name"
notion-cli page upload ./document.md
notion-cli page upload ./doc.md --title "自定义标题"
notion-cli page upload ./doc.md --parent "父页面名称"
Sync a markdown file (create or update)
同步markdown文件(创建或更新)
First run creates the page and writes notion-id to the file's frontmatter.
首次运行会创建页面,并将notion-id写入文件的前置元数据中。
Subsequent runs update the page content using the stored notion-id.
后续运行会使用存储的notion-id更新页面内容。
notion-cli page sync ./document.md
notion-cli page sync ./document.md --parent "Engineering" # Set parent on first sync
notion-cli page sync ./document.md --title "Custom Title"
notion-cli page sync ./document.md
notion-cli page sync ./document.md --parent "Engineering" # 首次同步时设置父页面
notion-cli page sync ./document.md --title "自定义标题"
Edit a page
编辑页面
notion-cli page edit <page> --replace "New content"
notion-cli page edit <page> --find "old text" --replace-with "new text"
notion-cli page edit <page> --find "section" --append "additional content"
undefinednotion-cli page edit <page> --replace "新内容"
notion-cli page edit <page> --find "旧文本" --replace-with "新文本"
notion-cli page edit <page> --find "章节" --append "附加内容"
undefinedDatabases
数据库
bash
notion-cli db list # List databases
notion-cli db list --json
notion-cli db query <database-url-or-id> # Query a database
notion-cli db query <id> --jsonbash
notion-cli db list # 列出数据库
notion-cli db list --json
notion-cli db query <database-url-or-id> # 查询数据库
notion-cli db query <id> --jsonComments
评论
bash
notion-cli comment list <page-id> # List comments on a page
notion-cli comment list <page-id> --json
notion-cli comment create <page-id> --content "Great work!"bash
notion-cli comment list <page-id> # 列出页面上的评论
notion-cli comment list <page-id> --json
notion-cli comment create <page-id> --content "做得好!"Output Formats
输出格式
Most commands support for machine-readable output:
--jsonbash
notion-cli page list --json | jq '.[0].url'
notion-cli search "api" --json | jq '.[] | .title'大多数命令支持参数以生成机器可读的输出:
--jsonbash
notion-cli page list --json | jq '.[0].url'
notion-cli search "api" --json | jq '.[] | .title'Tips for Agents
给Agent的提示
- Search first - Use to find pages before operating on them
notion-cli search - Use URLs or IDs - Both work for page/database references
- Check --help - Every command has detailed help:
notion-cli page edit --help - Raw output - Use with
--rawto see the original Notion markuppage view - JSON for parsing - Use when you need to extract specific fields
--json
- 先搜索 - 在操作页面之前,使用查找目标页面
notion-cli search - 使用URL或ID - 页面/数据库引用支持URL或ID两种方式
- 查看--help - 每个命令都有详细帮助信息:
notion-cli page edit --help - 原始输出 - 结合参数使用
--raw命令可查看原始Notion标记语言page view - JSON用于解析 - 当需要提取特定字段时,使用参数
--json