//native
/**
* Retrieve Block Children
* List the direct child blocks of a page or block (one level; recurse on blocks with `has_children`). Paginate with `next_cursor` as `start_cursor`.
*/
export async function main(
auth: RT.Notion,
block_id: string,
start_cursor: string | undefined,
page_size: number | undefined
) {
const url = new URL(`https://api.notion.com/v1/blocks/${block_id}/children`)
if (start_cursor !== undefined && start_cursor !== "") {
url.searchParams.append("start_cursor", start_cursor)
}
if (page_size !== undefined) {
url.searchParams.append("page_size", String(page_size))
}
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
"Notion-Version": "2026-03-11",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 6 days ago