1 | |
2 |
|
3 | |
4 | * Append Block Children |
5 | * Append Notion block objects (paragraphs, headings, to-dos, …) to a page or block, at the end or after a given child block. Up to 100 blocks per call. For plain text, Append Markdown to Page is simpler. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Notion, |
9 | block_id: string, |
10 | children: { [key: string]: any }[], |
11 | after_block_id: string | undefined |
12 | ) { |
13 | const body: { [key: string]: any } = { children } |
14 | if (after_block_id != null && after_block_id !== "") { |
15 | body.position = { type: "after_block", after_block: { id: after_block_id } } |
16 | } |
17 |
|
18 | const response = await fetch( |
19 | `https://api.notion.com/v1/blocks/${block_id}/children`, |
20 | { |
21 | method: "PATCH", |
22 | headers: { |
23 | Authorization: `Bearer ${auth.token}`, |
24 | "Content-Type": "application/json", |
25 | Accept: "application/json", |
26 | "Notion-Version": "2026-03-11", |
27 | }, |
28 | body: JSON.stringify(body), |
29 | } |
30 | ) |
31 |
|
32 | if (!response.ok) { |
33 | throw new Error(`${response.status} ${await response.text()}`) |
34 | } |
35 |
|
36 | return await response.json() |
37 | } |
38 |
|