notion

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

notion

Notion

Use the Notion API to create/read/update pages, data sources (databases), and blocks.
使用Notion API创建、读取、更新页面、data sources(数据库)和区块。

Setup

配置步骤

  1. Create an integration at https://notion.so/my-integrations
  2. Copy the API key (starts with
    ntn_
    or
    secret_
    )
  3. Store it:
bash
mkdir -p ~/.config/notion
echo "ntn_your_key_here" > ~/.config/notion/api_key
  1. Share target pages/databases with your integration (click "..." → "Connect to" → your integration name)
  1. https://notion.so/my-integrations 创建一个集成应用
  2. 复制API密钥(以
    ntn_
    secret_
    开头)
  3. 存储密钥:
bash
mkdir -p ~/.config/notion
echo "ntn_your_key_here" > ~/.config/notion/api_key
  1. 将目标页面/数据库共享给你的集成应用(点击“...” → “连接到” → 你的集成应用名称)

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: The
Notion-Version
header is required. This skill uses
2025-09-03
(latest). In this version, databases are called "data sources" in the API.
所有请求都需要包含以下内容:
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
请求头是必填项。本技能使用
2025-09-03
(最新版本)。在该版本中,API里的databases被称为"data sources"。

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
    /data_sources/
    endpoints for queries and retrieval
  • Two IDs: Each database now has both a
    database_id
    and a
    data_source_id
    • Use
      database_id
      when creating pages (
      parent: {"database_id": "..."}
      )
    • Use
      data_source_id
      when querying (
      POST /v1/data_sources/{id}/query
      )
  • Search results: Databases return as
    "object": "data_source"
    with their
    data_source_id
  • Parent in responses: Pages show
    parent.data_source_id
    alongside
    parent.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_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.database_id
    之外同时显示
    parent.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
    is_inline: true
    when creating data sources to embed them in pages
  • 页面/数据库ID为UUID格式(带或不带连字符)
  • API无法设置数据库视图筛选条件,这是仅UI端支持的功能
  • 速率限制:平均约3次请求/秒
  • 创建data source时设置
    is_inline: true
    可将其嵌入到页面中