Notion Manager
2026-03-28
新闻来源:网淘吧
围观:12
电脑广告
手机广告
notion
使用notion-cli来创建/读取/更新页面、数据源(数据库)和块。
设置
- 安装 notion-cli:
npm install -g @iansinnott/notion-cli - 在https://notion.so/my-integrations
- 创建一个集成复制 API 密钥(以ntn_或secret_
- 开头)
存储它:mkdir -p ~/.config/notion
- echo "ntn_your_key_here" > ~/.config/notion/api_key
将目标页面/数据库分享给你的集成(点击“...” → “连接到” → 你的集成名称)
用法所有命令都需要设置NOTION_TOKEN
export NOTION_TOKEN=$(cat ~/.config/notion/api_key)
环境变量:
-
搜索页面和数据源:
notion-cli search --query "页面标题" -
获取页面:
notion-cli page retrieve <页面ID> -
获取页面内容(块):
notion-cli page retrieve <页面ID> -r -
在数据库中创建页面:
curl -X POST https://api.notion.com/v1/pages \ -H "Authorization: Bearer $NOTION_TOKEN" \ -H "Content-Type: application/json" \ -H "Notion-Version: 2025-09-03" \ --data '{ "parent": { "database_id": "YOUR_DATABASE_ID" }, "properties": { "Name": { "title": [ { "text": { "content": "Nouvelle idée" } } ] } } }' -
查询数据库:
notion-cli db query <数据库ID> -a '{"property":"Status","status":{"equals":"Active"}}' -
更新页面属性:
curl -X PATCH https://api.notion.com/v1/pages/PAGE_ID \ -H "Authorization: Bearer $NOTION_TOKEN" \ -H "Content-Type: application/json" \ -H "Notion-Version: 2025-09-03" \ --data '{ "properties": { "Name": { "title": [ { "text": { "content": "Nouveau titre" } } ] }, "Status": { "status": { "name": "In progress" } }, "Priority": { "select": { "name": "High" } }, "Due date": { "date": { "start": "2026-02-10" } }, "Description": { "rich_text": [ { "text": { "content": "Description mise à jour" } } ] } } }' -
获取数据库信息:
notion-cli db retrieve <数据库ID>
属性类型
数据库项目的常用属性格式:
- 标题:
{"title": [{"text": {"content": "..."}}]} - 富文本:
{"rich_text": [{"text": {"content": "..."}}]} - 状态:
{"status": {"name": "选项"}} - 选择:
{"select": {"name": "选项"}} - 多选:
{"multi_select": [{"name": "A"}, {"name": "B"}]} - 日期:
{"date": {"start": "2024-01-15", "end": "2024-01-16"}} - 复选框:
{"checkbox": true} - 数字:
{"number": 42} - URL:
{"url": "https://..."} - 电子邮件:
{"email": "a@b.com"}
示例
-
搜索页面:
notion-cli search --query "AIStories" -
使用筛选器查询数据库:
notion-cli db query 2faf172c094981d3bbcbe0f115457cda \ -a '{ "property": "Status", "status": { "equals": "Backlog" } }' -
检索页面内容:
notion-cli page retrieve 2fdf172c-0949-80dd-b83b-c1df0410d91b -r -
更新页面状态:
curl -X PATCH https://api.notion.com/v1/pages/2fdf172c-0949-80dd-b83b-c1df0410d91b \ -H "Authorization: Bearer $NOTION_TOKEN" \ -H "Content-Type: application/json" \ -H "Notion-Version: 2025-09-03" \ --data '{ "properties": { "Status": { "status": { "name": "In progress" } } } }'
关键特性
- 交互模式:对于复杂查询,运行
notion-cli db query <DB_ID>不带参数时进入交互模式 - 多种输出格式:表格(默认)、CSV、JSON、YAML
- 原始JSON:使用
--raw标志获取完整的API响应 - 筛选语法:使用
-a标志处理包含AND/OR条件的复杂筛选器
注意事项
- 页面/数据库ID为UUID(可包含或不包含短横线)
- CLI通过NOTION_TOKEN
- 自动处理身份验证
- CLI会管理速率限制
使用notion-cli help
获取完整命令参考
- 参考链接GitHub Notion-CLI:
- https://github.com/litencatt/notion-clihttps://developers.notion.com
文章底部电脑广告
手机广告位-内容正文底部
上一篇:2Captcha CLI
下一篇:Audio Cog


微信扫一扫,打赏作者吧~