📖 Notion API 对接指南:用免费版 Notion 打造你的自动化知识库
<div class="meta">标签:<span class="tag-label">工具</span><span class="tag-label">效率</span></div>
<hr>
<p>很多人在用 Notion 免费版时会担心:API 功能是不是付费版才有的?实际上,<strong>Notion 的 API 对所有用户免费开放</strong>,无论你是免费版、个人版还是团队版,只要创建了 Integration,就能通过 API 读写 Notion 的内容。</p>
<p>本文详细介绍如何将 Notion 与 OpenClaw 对接,实现文档管理、知识库自动化、任务追踪等场景。</p>
<hr>
<h2>一、Notion API 核心概念</h2>
<h3>1.1 什么是 Integration?</h3>
<p>Integration 是 Notion 对外开放 API 的"身份凭证"。创建后,Integration 相当于一个机器人账号,可以读取和写入被授权的页面和数据库。</p>
<ul>
<li>API Key 格式:<code>ntn_</code> 或 <code>secret_</code> 开头</li>
<li>API 版本:目前使用 <code>2025-09-03</code>(最新)</li>
<li>创建地址:https://notion.so/my-integrations</li>
</ul>
<h3>1.2 免费版与付费版的区别</h3>
<table>
<tr><th>功能</th><th>免费版</th><th>付费版</th></tr>
<tr><td>API 读写页面</td><td>✅ 支持</td><td>✅ 支持</td></tr>
<tr><td>API 读写数据库</td><td>✅ 支持</td><td>✅ 支持</td></tr>
<tr><td>API 请求频率限制</td><td>~3次/秒</td><td>~3次/秒</td></tr>
<tr><td>页面版本历史</td><td>❌ 无</td><td>✅ 有</td></tr>
<tr><td>实时协作人数</td><td>10人</td><td>无限</td></tr>
</table>
<p><strong>结论:API 能力完全一样,付费版主要差在协作人数和高级分析功能。</strong></p>
<hr>
<h2>二、五分钟快速上手</h2>
<h3>步骤 1:创建 Notion Integration</h3>
<ol>
<li>打开 https://notion.so/my-integrations</li>
<li>点击 <strong>"New integration"</strong></li>
<li>填写名称(如"OpenClaw知识库")</li>
<li>选择关联的 Workspace</li>
<li>点击 <strong>Submit</strong>,复制生成的 API Key</li>
</ol>
<h3>步骤 2:配置到本地</h3>
<pre><code># 创建配置目录
mkdir -p ~/.config/notion
写入 API Key
echo "ntn_your_key_here" > ~/.config/notion/api_key
<h3>步骤 3:授权 Integration 访问页面</h3>
<p>这是免费版用户最容易卡住的地方:</p>
<ol>
<li>打开你要授权的 Notion 页面</li>
<li>点击右上角 <strong>"..."</strong>(更多操作)</li>
<li>选择 <strong>"Connections"</strong> → <strong>"Connect to"</strong></li>
<li>选择你创建的 Integration 名称</li>
</ol>
<blockquote>
⚠️ <strong>重要</strong>:没有被授权的页面,API 会报 <code>401 Unauthorized</code> 错误。
</blockquote>
<h3>步骤 4:验证连接</h3>
<pre><code>NOTION_KEY=$(cat ~/.config/notion/api_key)
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": "test"}'
<p>返回 200 即连接成功。</p>
<hr>
<h2>三、OpenClaw Notion Skill 常用命令</h2>
<h3>3.1 搜索页面和数据库</h3>
<pre><code>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": "项目文档"}'
<h3>3.2 读取页面内容</h3>
<pre><code># 获取页面基本信息
curl "https://api.notion.com/v1/pages/{page_id}" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03"
获取页面正文内容(blocks)
curl "https://api.notion.com/v1/blocks/{page_id}/children" \
-H "Authorization: Bearer $NOTION_KEY" \
-H "Notion-Version: 2025-09-03"
<h3>3.3 创建新页面</h3>
<pre><code>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": "你的数据库ID"},
"properties": {
"Name": {"title": [{"text": {"content": "新任务"}}]},
"Status": {"select": {"name": "Todo"}}
}
}'
<h3>3.4 查询数据库</h3>
<pre><code>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"}]
}'
<hr>
<h2>四、实战场景举例</h2>
<h3>场景 1:会议纪要自动归档</h3>
<p>每次会议结束后,OpenClaw 自动将纪要写入 Notion 的"会议记录"数据库,包含时间、参会人、决议事项。</p>
<h3>场景 2:项目任务追踪</h3>
<p>在 Notion 数据库中管理任务状态,OpenClaw 定时查询"待处理"任务,通过钉钉推送给相关人员。</p>
<h3>场景 3:知识库同步</h3>
<p>将 OpenClaw 处理过的文档、技术方案自动同步到 Notion,形成统一的知识沉淀。</p>
<hr>
<h2>五、注意事项</h2>
<ol>
<li><strong>频率限制</strong>:API 平均约 3 次/秒,收到 <code>429 rate_limited</code> 时根据 <code>Retry-After</code> 头等待后重试</li>
<li><strong>Payload 限制</strong>:每次最多 1000 个 block 元素,总大小 500KB</li>
<li><strong>权限必须手动授权</strong>:私人页面不开放给 Integration,API 读不到</li>
<li><strong>数据库改名为 Data Source</strong>:API 端点在 <code>2025-09-03</code> 版本中已将"数据库"改称"数据源",但创建页面时仍用 <code>database_id</code></li>
</ol>
<hr>
<h2>六、总结</h2>
<p>Notion 免费版完全支持 API 对接,能力与付费版无异。配合 OpenClaw 的 notion skill,可以轻松实现:</p>
<ul>
<li>📝 文档自动归档</li>
<li>✅ 任务状态追踪</li>
<li>🔍 知识库检索</li>
<li>📊 数据统计分析</li>
</ul>
<p>只需一个免费的 API Key,5 分钟就能跑通第一个场景。</p>
<hr>
<blockquote>
如有问题,欢迎通过钉钉联系 Raj。
</blockquote>