notion
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesenotion
Notion
Use the Notion API to create/read/update pages, data sources (databases), and blocks.
使用Notion API创建、读取、更新页面、data sources(数据库)和区块。
Setup
配置步骤
- Create an integration at https://notion.so/my-integrations
- Copy the API key (starts with or
ntn_)secret_ - Store it:
bash
mkdir -p ~/.config/notion
echo "ntn_your_key_here" > ~/.config/notion/api_key- Share target pages/databases with your integration (click "..." → "Connect to" → your integration name)
- 在 https://notion.so/my-integrations 创建一个集成应用
- 复制API密钥(以或
ntn_开头)secret_ - 存储密钥:
bash
mkdir -p ~/.config/notion
echo "ntn_your_key_here" > ~/.config/notion/api_key- 将目标页面/数据库共享给你的集成应用(点击“...” → “连接到” → 你的集成应用名称)
API Basics
API基础
All requests need:
bash
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"Note: Theheader is required. This skill usesNotion-Version(latest). In this version, databases are called "data sources" in the API.2025-09-03
所有请求都需要包含以下内容:
bash
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(最新版本)。在该版本中,API里的databases被称为"data sources"。2025-09-03
Common Operations
常见操作
Search for pages and data sources:
bash
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"}'Get page:
bash
curl "https://api.notion.com/v1/pages/{page_id}" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03"Get page content (blocks):
bash
curl "https://api.notion.com/v1/blocks/{page_id}/children" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03"Create page in a data source:
bash
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": "New Item"}}]},
"Status": {"select": {"name": "Todo"}}
}
}'Query a data source (database):
bash
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": "Active"}},
"sorts": [{"property": "Date", "direction": "descending"}]
}'Create a data source (database):
bash
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": "My Database"}}],
"properties": {
"Name": {"title": {}},
"Status": {"select": {"options": [{"name": "Todo"}, {"name": "Done"}]}},
"Date": {"date": {}}
}
}'Update page properties:
bash
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": {"Status": {"select": {"name": "Done"}}}}'Add blocks to page:
bash
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"}}]}}
]
}'搜索页面与data sources:
bash
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"}'获取页面:
bash
curl "https://api.notion.com/v1/pages/{page_id}" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03"获取页面内容(区块):
bash
curl "https://api.notion.com/v1/blocks/{page_id}/children" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03"在data source中创建页面:
bash
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": "New Item"}}]},
"Status": {"select": {"name": "Todo"}}
}
}'查询data source(数据库):
bash
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": "Active"}},
"sorts": [{"property": "Date", "direction": "descending"}]
}'创建data source(数据库):
bash
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": "My Database"}}],
"properties": {
"Name": {"title": {}},
"Status": {"select": {"options": [{"name": "Todo"}, {"name": "Done"}]}},
"Date": {"date": {}}
}
}'更新页面属性:
bash
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": {"Status": {"select": {"name": "Done"}}}}'向页面添加区块:
bash
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"}}]}}
]
}'Property Types
属性类型
Common property formats for database items:
- Title:
{"title": [{"text": {"content": "..."}}]} - Rich text:
{"rich_text": [{"text": {"content": "..."}}]} - Select:
{"select": {"name": "Option"}} - Multi-select:
{"multi_select": [{"name": "A"}, {"name": "B"}]} - Date:
{"date": {"start": "2024-01-15", "end": "2024-01-16"}} - Checkbox:
{"checkbox": true} - Number:
{"number": 42} - URL:
{"url": "https://..."} - Email:
{"email": "a@b.com"} - Relation:
{"relation": [{"id": "page_id"}]}
数据库项的常见属性格式:
- 标题:
{"title": [{"text": {"content": "..."}}]} - 富文本:
{"rich_text": [{"text": {"content": "..."}}]} - 单选:
{"select": {"name": "Option"}} - 多选:
{"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"}]}
Key Differences in 2025-09-03
2025-09-03版本的主要差异
- Databases → Data Sources: Use endpoints for queries and retrieval
/data_sources/ - Two IDs: Each database now has both a and a
database_iddata_source_id- Use when creating pages (
database_id)parent: {"database_id": "..."} - Use when querying (
data_source_id)POST /v1/data_sources/{id}/query
- Use
- Search results: Databases return as with their
"object": "data_source"data_source_id - Parent in responses: Pages show alongside
parent.data_source_idparent.database_id - Finding the data_source_id: Search for the database, or call
GET /v1/data_sources/{data_source_id}
- Databases → Data Sources: 使用端点进行查询和检索
/data_sources/ - 双ID机制: 每个数据库现在同时拥有和
database_iddata_source_id- 在创建页面时使用(
database_id)parent: {"database_id": "..."} - 在查询时使用(
data_source_id)POST /v1/data_sources/{id}/query
- 在创建页面时使用
- 搜索结果: 数据库会以的形式返回,包含其
"object": "data_source"data_source_id - 响应中的父级信息: 页面会在之外同时显示
parent.database_idparent.data_source_id - 查找data_source_id: 搜索该数据库,或调用接口
GET /v1/data_sources/{data_source_id}
Notes
注意事项
- Page/database IDs are UUIDs (with or without dashes)
- The API cannot set database view filters — that's UI-only
- Rate limit: ~3 requests/second average
- Use when creating data sources to embed them in pages
is_inline: true
- 页面/数据库ID为UUID格式(带或不带连字符)
- API无法设置数据库视图筛选条件,这是仅UI端支持的功能
- 速率限制:平均约3次请求/秒
- 创建data source时设置可将其嵌入到页面中
is_inline: true