Open3

NotionAPIの使い方

uouo

Create Page

https://developers.notion.com/reference/post-page

properties

https://developers.notion.com/reference/page#property-value-object

API実行例

curl 'https://api.notion.com/v1/pages' \
  -H 'Authorization: Bearer {NOTION_API_KEY}' \
  -H "Content-Type: application/json" \
  -H "Notion-Version: 2021-08-16" \
  --data '{
    "parent": { "database_id": {DATABASE_ID} },
    "properties": {
        "Name": {
            "title": [
                {
                    "text": {
                        "content": "Title"
                    }
                }
            ]
        },
        "DateRange": {
            "date":{
                    "start": "2021-10-12",
                    "end": "2022-04-12"
                }
        },
        "RichText": {
            "rich_text": [
                {
                    "type": "text",
                    "text": {
                      "content": "あああ"
                    }
                }
            ]
        },
        "Image": {
            "files": [
                {
                  "type": "external",
                  "name": "Space Wallpaper",
                  "external": {
                      "url":"https://website.domain/images/space.pn"
                  }
                }
            ]
        },
        "Checkbox": {
            "checkbox": true
        },
        "Link": {
            "url": "http://example.com"
        }
    }
}'
uouo

Query a Database

https://developers.notion.com/reference/post-database-query

メモ

データベースに紐づくページを取得できる

  • 1回に取得できるページの上限数は100件
    • 100件以上ページがある場合は、レスポンスに以下が含まれる
      • {"next_cursor":"hogehoge","has_more":true}
        • リクエストパラメータのstart_cursorを指定して続きから取得する

リクエスト例

curl -X POST "https://api.notion.com/v1/databases/{DATABASE_ID}/query" \
  -H "Authorization: Bearer  {NOTION_API_KEY}" \
  -H "Notion-Version: 2021-08-16" \
  -H "Content-Type: application/json"