はい、Notion APIのページオブジェクトに関するドキュメントを確認しました。ご質問があれば、お気軽にどうぞ。可能な限り詳しくお答えいたします。
ページIDが既に分かっている場合、Notion API では以下の流れでそのページの情報と中身を取得できます:
GET <https://api.notion.com/v1/pages/{page_id}>
ページ本文(見出しや段落などのブロック)は以下のエンドポイントで取得します:
GET <https://api.notion.com/v1/blocks/{page_id}/children?page_size=100>
page_id
を block_id
として指定し、最初の100件の子ブロックを取得できます。has_children: true
)の場合は、そのブロックをさらに再帰的に同じエンドポイントで取得していく必要があります(Notion Developers)。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;
}
この方法で、ページ内のすべてのブロック(テキスト・見出し・リスト・画像など)を含む構造を取得できます。