Notion
2026-03-23
新闻来源:网淘吧
围观:79
电脑广告
手机广告
购买adidas上京东官方旗舰店。
notion
使用 Notion API 来创建/读取/更新页面、数据源(数据库)和块。
设置
- 在https://notion.so/my-integrations
- 创建一个集成
复制 API 密钥(以ntn_或secret_ - 开头)
存储它:
- mkdir -p ~/.config/notion echo "ntn_your_key_here" > ~/.config/notion/api_key
将目标页面/数据库分享给你的集成(点击"..." → "连接到" → 你的集成名称)
API 基础
上网淘巴领天猫淘宝优惠券,一年省好几千。所有请求都需要:
NOTION_KEY=$(cat ~/.config/notion/api_key) curl -X GET "https://api.notion.com/v1/..." \ -H "Authorization: Bearer $NOTION_KEY" \ -H "Notion-Version: 2025-09-03" \ -H "Content-Type: application/json"注意:
Notion-Version请求头是必需的。本技能使用2025-09-03(最新版)。在此版本中,数据库在 API 中被称为"数据源"。
常见操作
搜索页面和数据源:
curl -X POST "https://api.notion.com/v1/search" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{"query": "page title"}'
获取页面:
curl "https://api.notion.com/v1/pages/{page_id}" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03"
获取页面内容(区块):
curl "https://api.notion.com/v1/blocks/{page_id}/children" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03"
在数据源中创建页面:
curl -X POST "https://api.notion.com/v1/pages" \
-H "Authorization: Bearer $NOTION_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 -X POST "https://api.notion.com/v1/data_sources/{data_source_id}/query" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{
"filter": {"property": "Status", "select": {"equals": "进行中"}},
"sorts": [{"property": "日期", "direction": "descending"}]
}'
创建数据源(数据库):
curl -X POST "https://api.notion.com/v1/data_sources" \
-H "Authorization: Bearer $NOTION_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 -X PATCH "https://api.notion.com/v1/pages/{page_id}" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{"properties": {"状态": {"select": {"name": "已完成"}}}}'
向页面添加区块:
curl -X PATCH "https://api.notion.com/v1/blocks/{page_id}/children" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03" \
-H "Content-Type: application/json" \
-d '{
"children": [
{"object": "block", "type": "paragraph", "paragraph": {"rich_text": [{"text": {"content": "Hello"}}]}}
]
}'
属性类型
数据库项目的常用属性格式:
- 标题:
{"title": [{"text": {"content": "..."}}]} - 富文本:
{"rich_text": [{"text": {"content": "..."}}]} - 选择:
{"select": {"name": "选项"}} - 多选:
{"multi_select": [{"name": "A"}, {"name": "B"}]} - 日期:
{"date": {"start": "2024-01-15", "end": "2024-01-16"}} - 复选框:
{"checkbox": true} - 数字:
{"number": 42} - 网址:
{"url": "https://..."} - 电子邮件:
{"email": "a@b.com"} - 关联:
{"relation": [{"id": "page_id"}]}
2025-09-03 的主要差异
- 数据库 → 数据源:使用
/data_sources/端点进行查询和检索 - 两个ID:现在每个数据库都有
database_id和data_source_id- 使用
database_id创建页面时(parent: {"database_id": "..."}使用 - data_source_id
进行查询时(POST /v1/data_sources/{id}/query)搜索结果:
- 使用
- 数据库返回为"object": "data_source"
并包含其data_source_id响应中的父级信息: - 页面显示parent.data_source_id
以及parent.database_id查找 data_source_id: - 搜索数据库,或调用GET /v1/data_sources/{data_source_id}
注意事项
页面/数据库ID为UUID(可带或不带连字符)
- API无法设置数据库视图过滤器——此功能仅限于用户界面
- 速率限制:平均约每秒3个请求
- 创建数据源以嵌入页面时,请使用
- is_inline: true
is_inline: truewhen creating data sources to embed them in pages
文章底部电脑广告
手机广告位-内容正文底部
上一篇:Sonoscli
下一篇:Nano Banana Pro


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