AgentSkillsCN

api-notion

Notion REST API 用于页面、数据库、区块管理。采用内部集成 Token 实现无头模式或 CI 自动化操作。适用于 Notion 相关的各类运维场景。

SKILL.md
--- frontmatter
name: api-notion
description: Notion REST API for pages, databases, blocks. Uses internal integration token for headless/CI. Activate for Notion operations.
allowed-tools: Bash, Read, Grep
user-invocable: true

Notion API Skill

When to Activate

  • Read/create/update pages
  • Query databases
  • Manage blocks and content
  • Search workspace

Authentication

Credentials File: .credentials/notion.json

json
{
  "api_token": "ntn_..."
}

Create internal integration at: https://www.notion.so/my-integrations

Important: Pages must be shared with the integration to be accessible.

Load credentials before API calls:

bash
NOTION_API_TOKEN=$(jq -r '.api_token' /Users/dhlee/Git/personal/neuron/.credentials/notion.json)

API Base URL

code
https://api.notion.com/v1

Required Headers

code
Authorization: Bearer $NOTION_API_TOKEN
Notion-Version: 2022-06-28
Content-Type: application/json

Common Operations

List Users

bash
curl -s -H "Authorization: Bearer $NOTION_API_TOKEN" \
  -H "Notion-Version: 2022-06-28" \
  https://api.notion.com/v1/users

Search

bash
curl -s -X POST \
  -H "Authorization: Bearer $NOTION_API_TOKEN" \
  -H "Notion-Version: 2022-06-28" \
  -H "Content-Type: application/json" \
  -d '{"query": "search term", "filter": {"property": "object", "value": "page"}}' \
  https://api.notion.com/v1/search

Get Page

bash
curl -s -H "Authorization: Bearer $NOTION_API_TOKEN" \
  -H "Notion-Version: 2022-06-28" \
  https://api.notion.com/v1/pages/{page_id}

Query Database

bash
curl -s -X POST \
  -H "Authorization: Bearer $NOTION_API_TOKEN" \
  -H "Notion-Version: 2022-06-28" \
  -H "Content-Type: application/json" \
  -d '{"filter": {"property": "Status", "select": {"equals": "Done"}}}' \
  https://api.notion.com/v1/databases/{database_id}/query

Create Page in Database

bash
curl -s -X POST \
  -H "Authorization: Bearer $NOTION_API_TOKEN" \
  -H "Notion-Version: 2022-06-28" \
  -H "Content-Type: application/json" \
  -d '{
    "parent": {"database_id": "{database_id}"},
    "properties": {
      "Name": {"title": [{"text": {"content": "New page title"}}]},
      "Status": {"select": {"name": "In Progress"}}
    }
  }' \
  https://api.notion.com/v1/pages

Append Block Children

bash
curl -s -X PATCH \
  -H "Authorization: Bearer $NOTION_API_TOKEN" \
  -H "Notion-Version: 2022-06-28" \
  -H "Content-Type: application/json" \
  -d '{
    "children": [
      {
        "object": "block",
        "type": "paragraph",
        "paragraph": {
          "rich_text": [{"type": "text", "text": {"content": "New paragraph"}}]
        }
      }
    ]
  }' \
  https://api.notion.com/v1/blocks/{block_id}/children

Get Block Children

bash
curl -s -H "Authorization: Bearer $NOTION_API_TOKEN" \
  -H "Notion-Version: 2022-06-28" \
  "https://api.notion.com/v1/blocks/{block_id}/children?page_size=100"

Error Handling

StatusMeaningAction
401Invalid tokenCheck .credentials/notion.json
403Page not sharedShare page with integration
404Resource not foundVerify page/database ID
429Rate limitedWait and retry

Rate Limits

  • 3 requests per second average
  • Implement exponential backoff

References