コメント用の新しい API がリリースされました。

概要説明

本日、Notion のコメントに関する新しい API セットをリリースします。これには以下の機能が含まれます。

詳しい情報は、新しい ガイド (翻訳版→ガイド: コメントの操作 )または API reference を参照してください。

検証

まず、API test インテグレーションの二つの機能を追加しました(チェックが入っていなかったので追加しました)。

Untitled

ページにコメントを追加する

ガイドにあったスクリプトを実行してみます。

curl -X POST <https://api.notion.com/v1/comments> \\
  -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\
  -H "Content-Type: application/json" \\
  -H "Notion-Version: 2022-06-28" \\
  --data '
  {
    "parent": {
      "page_id": "59e3eb41-33b2-4151-b05b-31115a15e1c2"
    },
    "rich_text": [
      {
        "text": {
          "content": "Hello from my integration."
        }
      }
    ]
  }

応答はこんな感じになりました。

{
  "object": "comment",
  "id": "c9329903-0f94-43e3-9006-916d72a4d402",
  "parent": {
    "type": "page_id",
    "page_id": "d1209dcd-ac48-4263-920a-e8e82ff0aefd"
  },
  "discussion_id": "025afea0-f3b2-4fa5-bbcc-9b23dae28406",
  "created_time": "2022-07-21T05:06:00.000Z",
  "last_edited_time": "2022-07-21T05:06:00.000Z",
  "created_by": {
    "object": "user",
    "id": "9497f745-1d35-4311-b127-f0c757adb870"
  },
  "rich_text": [
    {
      "type": "text",
      "text": {
        "content": "Hello from my integration.",
        "link": null
      },
      "annotations": {
        "bold": false,
        "italic": false,
        "strikethrough": false,
        "underline": false,
        "code": false,
        "color": "default"
      },
      "plain_text": "Hello from my integration.",
      "href": null
    }
  ]
}

ページまたはブロックのコメントを一覧表示する

ガイドにあったスクリプトを実行してみます。

curl '<https://api.notion.com/v1/comments?block_id=d1209dcdac484263920ae8e82ff0aefd>'\\
  -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\
  -H "Notion-Version: 2022-06-28"

応答はこんな感じになりました。

{
  "object": "list",
  "results": [
    {
      "object": "comment",
      "id": "c9329903-0f94-43e3-9006-916d72a4d402",
      "parent": {
        "type": "page_id",
        "page_id": "d1209dcd-ac48-4263-920a-e8e82ff0aefd"
      },
      "discussion_id": "025afea0-f3b2-4fa5-bbcc-9b23dae28406",
      "created_time": "2022-07-21T05:06:00.000Z",
      "last_edited_time": "2022-07-21T05:06:00.000Z",
      "created_by": {
        "object": "user",
        "id": "9497f745-1d35-4311-b127-f0c757adb870"
      },
      "rich_text": [
        {
          "type": "text",
          "text": {
            "content": "Hello from my integration.",
            "link": null
          },
          "annotations": {
            "bold": false,
            "italic": false,
            "strikethrough": false,
            "underline": false,
            "code": false,
            "color": "default"
          },
          "plain_text": "Hello from my integration.",
          "href": null
        }
      ]
    }
  ],
  "next_cursor": null,
  "has_more": false,
  "type": "comment",
  "comment": {}
}

ディスカッションスレッドへの返信

コメントを取得するには、discussion_id が必要です。上の comment の一覧に書かれています。または、以下のようにコメントのリンクから取得することができます。

Untitled

URL はこんな感じになっています。d の後ろが discussion_id とのことです。この場合、025afea0f3b24fa5bbcc9b23dae28406 が discussion_id です。確かに上の JSON の結果と一致しています。