Hi ChatGPT! Can you please read this page and prepare to answer questions about it?

はい、Notion APIのページオブジェクトに関するドキュメントを確認しました。ご質問があれば、お気軽にどうぞ。可能な限り詳しくお答えいたします。

ページIDが既に分かっている場合、そのページの内容を得るにはどのようにすればよいですか?

ページIDが既に分かっている場合、Notion API では以下の流れでそのページの情報と中身を取得できます:


📄 1. ページのプロパティを取得する

GET <https://api.notion.com/v1/pages/{page_id}>


🧱 2. ページ内容のブロックを取得する

ページ本文(見出しや段落などのブロック)は以下のエンドポイントで取得します:

GET <https://api.notion.com/v1/blocks/{page_id}/children?page_size=100>

再帰処理の流れ(疑似コード)

async function fetchAllBlocks(blockId) {
  let blocks = [];
  let cursor = null;
  do {
    const res = await notion.blocks.children.list({
      block_id: blockId,
      start_cursor: cursor,
      page_size: 100,
    });
    for (const b of res.results) {
      blocks.push(b);
      if (b.has_children) {
        b.children = await fetchAllBlocks(b.id);
      }
    }
    cursor = res.has_more ? res.next_cursor : null;
  } while (cursor);
  return blocks;
}

この方法で、ページ内のすべてのブロック(テキスト・見出し・リスト・画像など)を含む構造を取得できます。


✅ まとめ