1

Append Block Children

by
Published Jun 6, 2022

Append Notion block objects to a page or block, at the end or after a given child block.

Script notion Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 3 days ago
1
//native
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 !== undefined && 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

Other submissions
  • Submitted by adam186 Deno
    Created 516 days ago
    1
    import { Client } from "npm:@notionhq/client";
    2
    import type { BlockObjectRequest } from "npm:@notionhq/client/2.2.4/build/src/api-endpoints.js";
    3
    
    
    4
    /**
    5
     * Learn more at
    6
     * https://developers.notion.com/reference/patch-block-children
    7
     */
    8
    type Notion = {
    9
      token: string;
    10
    };
    11
    export async function main(
    12
      auth: Notion,
    13
      block_id: string,
    14
      children: object[] = [],
    15
    ) {
    16
      const client = new Client({ auth: auth.token });
    17
      return await client.blocks.children.append({
    18
        block_id,
    19
        children: children as BlockObjectRequest,
    20
      });
    21
    }
    22
    
    
  • Submitted by hugo989 Bun
    Created 124 days ago
    1
    import { Client } from "@notionhq/client";
    2
    import type { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
    3
    
    
    4
    /**
    5
     * Learn more at
    6
     * https://developers.notion.com/reference/patch-block-children
    7
     */
    8
    type Notion = {
    9
      token: string;
    10
    };
    11
    export async function main(
    12
      auth: Notion,
    13
      block_id: string,
    14
      children: object[] = [],
    15
    ) {
    16
      const client = new Client({ auth: auth.token });
    17
      return await client.blocks.children.append({
    18
        block_id,
    19
        children: children as BlockObjectRequest,
    20
      });
    21
    }
    22