微算力 · API 导航与自营网关
API 接入 EN
未登录登录
📝

官方 API 自动化管理 Notion 工作区

MH notion · v1.0.0
办公 安全 B 级 作者 mohdalhashemi98-hue 公开目录收录
1.1k 下载 0 安装 5.3k 收藏 24 浏览

简介

官方 Notion API,支持页面/数据库/块的增删改查,适合构建自动化工作流与知识库集成,需妥善保管 API Key。

原始描述

Notion API for creating and managing pages, databases, and blocks.

通过你的 Agent 添加

安装目录:notion/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/mh-notion/
Codex CLI~/.codex/skills/mh-notion/
DeepSeek Harness~/.agents/skills/mh-notion/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

Notion Skill 基于官方 REST API,提供对页面(Pages)、数据源(Databases,API 中称为 data sources)和块(Blocks)的完整 CRUD 操作能力。用户需先在 Notion 后台创建 Integration 并获取以 ntn_ 或 secret_ 开头的 API Key,通过环境变量 NOTION_API_KEY 注入。

关键流程:

  1. 认证:所有请求需在 Header 携带 Authorization: Bearer {KEY} 及 Notion-Version: 2025-09-03
  2. 授权:必须手动将目标页面/数据库与 Integration 共享(⚙️ → "Connect to")
  3. 操作:支持搜索、查询数据源、创建页面、更新属性、追加块内容等

2025-09-03 版本重大变更:

  • 数据库概念拆分为 database_id(用于创建页面时的 parent)和 data_source_id(用于查询端点)
  • 端点路径从 /databases 迁移至 /data_sources

显著优点

  • 官方原生:Notion 官方维护,API 与产品功能同步更新
  • 功能完备:覆盖从简单文本块到复杂关系型数据库的全部能力
  • 结构化数据:支持 Select、Multi-select、Date、Relation 等丰富属性类型,适合构建轻量级 CMS 或任务系统
  • 版本明确:强制 Notion-Version Header,避免破坏性更新导致故障

潜在缺点与局限性

  • 权限粒度粗:Integration 需手动共享,无法基于规则自动授权;删除权限一旦授予即全局生效
  • 速率限制:约 3 req/s 的平均限制,高频场景需引入队列或缓存
  • UI 功能缺失:数据库视图筛选、公式计算结果等无法通过 API 设置
  • ID 管理复杂:UUID 格式的 page/database/block ID 需人工维护,调试成本高

适合人群

  • 个人/团队希望将 Notion 作为后端数据库,构建自动化工作流(如同步 GitHub Issues、日历事件)
  • 开发者需要快速搭建内容管理原型,但无需传统数据库的复杂事务支持
  • 已有 Notion 工作流,希望通过 API 实现批量数据迁移或报表生成

常规风险

风险类型 说明
密钥泄露 API Key 拥有 Integration 的全部权限,泄露后可被用于读取/篡改所有共享数据
数据误删 API 支持硬删除操作,缺乏回收站保护机制
速率超限 突发流量易触发 429 错误,需实现指数退避重试
版本漂移 未来 API 版本升级可能导致当前调用模式废弃,需关注官方迁移指南

技能正文


name: notion description: Notion API for creating and managing pages, databases, and blocks. homepage: https://developers.notion.com metadata: { "openclaw": { "emoji": "📝", "requires": { "env": ["NOTION_API_KEY"] }, "primaryEnv": "NOTION_API_KEY" }, }

notion

Use the Notion API to create/read/update pages, data sources (databases), and blocks.

Setup

  1. Create an integration at https://notion.so/my-integrations
  2. Copy the API key (starts with ntn_ or secret_)
  3. Store it:
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)

API Basics

All requests need:

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.

Common Operations

Search for pages and data sources:

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:

curl "https://api.notion.com/v1/pages/{page_id}" \
  -H "Authorization: Bearer $NOTION_KEY" \
  -H "Notion-Version: 2025-09-03"

Get page content (blocks):

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:

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):

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):

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:

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:

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"}]}

Key Differences in 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}

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

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

notionapidatabasecmsknowledge-managementautomationproductivity

同类 Skill