通过 curl 操作 Notion API:页面、数据库、块、搜索
通过 curl 调用 Notion API,创建、读取、更新页面、数据库(数据源)和块。无需额外工具——仅需 curl 和 Notion API key。
ntn_ 或 secret_ 开头)~/.hermes/.env:
NOTION_API_KEY=ntn_your_key_here
所有请求使用此模式:
curl -s -X GET "https://api.notion.com/v1/..." \
-H "Authorization: Bearer $NOTION_API_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json"
Notion-Version 请求头是必须的。本技能使用 2025-09-03(最新版)。该版本中,API 将 database 称为 "data source"。
curl -s -X POST "https://api.notion.com/v1/search" \
-H "Authorization: Bearer $NOTION_API_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{"query": "页面标题"}'
curl -s "https://api.notion.com/v1/pages/{page_id}" \
-H "Authorization: Bearer $NOTION_API_KEY" \
-H "Notion-Version: 2025-09-03"
curl -s "https://api.notion.com/v1/blocks/{page_id}/children" \
-H "Authorization: Bearer $NOTION_API_KEY" \
-H "Notion-Version: 2025-09-03"
curl -s -X POST "https://api.notion.com/v1/pages" \
-H "Authorization: Bearer $NOTION_API_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{
"parent": {"database_id": "xxx"},
"properties": {
"Name": {"title": [{"text": {"content": "新条目"}}]},
"Status": {"select": {"name": "待办"}}
}
}'
curl -s -X POST "https://api.notion.com/v1/data_sources/{data_source_id}/query" \
-H "Authorization: Bearer $NOTION_API_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{
"filter": {"property": "状态", "select": {"equals": "进行中"}},
"sorts": [{"property": "日期", "direction": "descending"}]
}'
curl -s -X POST "https://api.notion.com/v1/data_sources" \
-H "Authorization: Bearer $NOTION_API_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{
"parent": {"page_id": "xxx"},
"title": [{"text": {"content": "我的数据库"}}],
"properties": {
"名称": {"title": {}},
"状态": {"select": {"options": [{"name": "待办"}, {"name": "已完成"}]}},
"日期": {"date": {}}
}
}'
curl -s -X PATCH "https://api.notion.com/v1/pages/{page_id}" \
-H "Authorization: Bearer $NOTION_API_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{"properties": {"状态": {"select": {"name": "已完成"}}}}'
curl -s -X PATCH "https://api.notion.com/v1/blocks/{page_id}/children" \
-H "Authorization: Bearer $NOTION_API_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{
"children": [
{"object": "block", "type": "paragraph", "paragraph": {"rich_text": [{"text": {"content": "来自 Hermes 的问候!"}}]}}
]
}'
数据库条目的常见属性格式:
{"title": [{"text": {"content": "..."}}]}{"rich_text": [{"text": {"content": "..."}}]}{"select": {"name": "选项"}}{"multi_select": [{"name": "A"}, {"name": "B"}]}{"date": {"start": "2026-01-15", "end": "2026-01-16"}}{"checkbox": true}{"number": 42}{"url": "https://..."}{"email": "user@example.com"}{"relation": [{"id": "page_id"}]}/data_sources/ 端点进行查询和检索database_id 和 data_source_iddatabase_id(parent: {"database_id": "..."})data_source_id(POST /v1/data_sources/{id}/query)"object": "data_source" 并携带 data_source_idis_inline: true 可将其嵌入页面中-s 标志可隐藏进度条(Hermes 输出更清晰)jq 管道输出可读的 JSON:... | jq '.results[0].properties'
评论区