Notion Helper - v1.3.29
    Preparing search index...

    Function appendBlocks

    • Function

      Appends a children block array to a parent block (or page). Handles nested blocks to any level via recursion.

      Parameters

      • options: {
            block_id: string;
            children: Object[];
            client?: Object;
            apiCall?: Function;
            getResults?: Function;
        }

        The options for appending blocks.

        • block_id: string

          The ID of the parent block to append children to. Can be a page ID.

        • children: Object[]

          An array of child blocks to append.

        • Optionalclient?: Object

          The Notion client object. Either this or apiCall must be provided.

        • OptionalapiCall?: Function

          A custom function for making API calls. Receives { type: 'append_blocks', data: { block_id, children, after } } as argument. Either this or client must be provided.

        • OptionalgetResults?: Function

          A function to extract results from the API response. Defaults to response => response.results, which will work if you pass a client object created with the Notion SDK: https://github.com/makenotion/notion-sdk-js. If you're passing a custom apiCall function, you should provide a matching getResults function that can handle the response and return the results array, which contains the created blocks.

      Returns Promise<Object>

      An object containing the API responses and the total number of API calls made.

      RequestShorthand

      If there's an error during the API call or block appending process.

      // Using with Notion SDK client
      const notion = new Client({ auth: NOTION_TOKEN });
      const childBlocks = createNotion().paragraph("A paragraph").build()

      const { apiResponses, apiCallCount } = await appendBlocks({
      block_id: 'your-block-id',
      children: childBlocks.content,
      client: notion
      });

      // Using with custom API call function (using ky)
      import ky from 'ky';

      const NOTION_TOKEN = 'your-notion-token';

      const apiCall = async ({ type, data }) => {
      const { block_id, children, after } = data;
      const response = await ky.patch(
      `https://api.notion.com/v1/blocks/${block_id}/children`,
      {
      json: { children, ...(after && { after }) },
      headers: {
      'Authorization': `Bearer ${NOTION_TOKEN}`,
      'Notion-Version': '2025-09-03',
      },
      }
      ).json();
      return response;
      };

      const childBlocks = createNotion().paragraph("Hello, World!").build();

      const { apiResponses, apiCallCount } = await appendBlocks({
      block_id: 'your-block-id',
      children: childBlocks.content,
      apiCall
      });