闲社服务运行正常AI智能体自动化平台
o

Notion API 工具

技能标识:openclaw-notion-api

Notion API 用于创建和管理页面、数据库和块。包含正确的图片、文件上传功能

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 0.1.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

Notion API 工具

openclaw-notion-api

使用 Notion API 创建/读取/更新页面、数据源(数据库)和块。

设置

  1. 1. 在 https://www.notion.so/profile/integrations/internal 创建内部集成
  2. 复制 API 密钥(以 ntn 或 secret 开头)
  3. 存储密钥:
bash mkdir -p ~/.config/notion echo ntnyourkeyhere > ~/.config/notion/apikey
  1. 4. 将目标页面/数据库与集成共享(点击 ... → 连接到 → 你的集成名称)

API 基础

所有请求都需要:
bash
NOTIONKEY=$(cat ~/.config/notion/apikey)
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 中称为数据源。

常用操作

搜索页面和数据源:
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: 页面标题}

获取页面:
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

在数据源中创建页面:
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: xxxxxx},
properties: {
名称: {title: [{text: {content: 新项目}}]},
状态: {select: {name: 待办}}
}
}

查询数据源(数据库):
bash
curl -X POST https://api.notion.com/v1/datasources/{datasource_id}/query \
-H Authorization: Bearer $NOTION_KEY \
-H Notion-Version: 2025-09-03 \
-H Content-Type: application/json \
-d {
filter: {property: 状态, select: {equals: 活跃}},
sorts: [{property: 日期, direction: 降序}]
}

创建数据源(数据库):
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: 我的数据库}}],
properties: {
名称: {title: {}},
状态: {select: {options: [{name: 待办}, {name: 完成}]}},
日期: {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: {状态: {select: {name: 完成}}}}

向页面添加块:
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: [
{type: paragraph, paragraph: {rich_text: [{text: {content: 你好}}]}}
]
}

属性类型

数据库项的常用属性格式:

  • - 标题: {title: [{text: {content: ...}}]}
  • 富文本: {richtext: [{text: {content: ...}}]}
  • 选择: {select: {name: 选项}}
  • 多选: {multiselect: [{name: A}, {name: B}]}
  • 日期: {date: {start: 2024-01-15, end: 2024-01-16}}
  • 复选框: {checkbox: true}
  • 数字: {number: 42}
  • URL: {url: https://...}
  • 邮箱: {email: a@b.com}
  • 关联: {relation: [{id: page_id}]}

2025-09-03 版本的关键差异

  • - 数据库 → 数据源: 使用 /datasources/ 端点进行查询和检索
  • 双 ID: 每个数据库现在同时拥有 databaseid 和 datasourceid
- 创建页面时使用 databaseid(parent: {databaseid: ...}) - 查询时使用 datasourceid(POST /v1/data_sources/{id}/query)
  • - 搜索结果: 数据库以 object: datasource 形式返回,并带有其 datasourceid
  • 响应中的父级: 页面显示 parent.datasourceid 以及 parent.databaseid
  • 查找 datasourceid: 搜索数据库,或调用 GET /v1/datasources/{datasource_id}

文件上传

使用直接上传方法上传图片或文件到 Notion(文件大小不超过 20MB)。两者的步骤完全相同,仅在步骤 3 的块类型上有区别。

步骤 1:创建文件上传对象

创建上传对象以获取上传 URL:
bash
curl --request POST \
--url https://api.notion.com/v1/file_uploads \
-H Authorization: Bearer $NOTION_KEY \
-H Content-Type: application/json \
-H Notion-Version: 2025-09-03 \
--data {}

响应包含:

  • - id:文件上传 ID(在步骤 3 中使用)
  • upload_url:上传文件内容的 URL

步骤 2:上传文件内容

使用 multipart/form-data 上传实际的文件:
bash
curl --request POST \
--url https://api.notion.com/v1/fileuploads/{fileupload_id}/send \
-H Authorization: Bearer $NOTION_KEY \
-H Notion-Version: 2025-09-03 \
-H Content-Type: multipart/form-data \
-F file=@/path/to/file.png

重要:

  • - 使用 POST 方法(不是 PUT)
  • 包含 Authorization 和 Notion-Version 请求头
  • 使用 -F 进行 multipart/form-data
  • 文件大小必须 ≤ 20MB

步骤 3:插入到页面

将上传的文件作为块添加。根据文件类型选择不同的块类型:

上传图片:
bash
curl --request PATCH \
--url https://api.notion.com/v1/blocks/{page_id}/children \
-H Authorization: Bearer $NOTION_KEY \
-H Content-Type: application/json \
-H Notion-Version: 2025-09-03 \
--data {
children: [
{
type: image,
image: {
type: file_upload,
file_upload: {
id: {fileuploadid}

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 openclaw-notion-api-1776301884 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 openclaw-notion-api-1776301884 技能

通过命令行安装

skillhub install openclaw-notion-api-1776301884

下载

⬇ 下载 openclaw-notion-api v0.1.0(免费)

文件大小: 5.81 KB | 发布时间: 2026-4-16 16:44

v0.1.0 最新 2026-4-16 16:44
Initial release of openclaw-notion-api skill.

- Provides guides and sample curl commands for Notion API operations including creating, reading, and updating pages, databases (data sources), and blocks.
- Documents 2025-09-03 API changes: databases are now "data sources", with new endpoints and dual IDs.
- Includes detailed instructions and examples for uploading and attaching files or images (<20MB) via Notion’s new direct file upload method.
- Lists common property types and demonstrates their API payload formats.
- Details common error scenarios and provides setup instructions for Notion API authentication.
返回顶部