Edits history of script submission #23067 for ' Append Block Children (notion)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Append Block Children
     * 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.
     */
    export async function main(
      auth: RT.Notion,
      block_id: string,
      children: { [key: string]: any }[],
      after_block_id: string | undefined
    ) {
      const body: { [key: string]: any } = { children }
      if (after_block_id !== undefined && after_block_id !== "") {
        body.position = { type: "after_block", after_block: { id: after_block_id } }
      }
    
      const response = await fetch(
        `https://api.notion.com/v1/blocks/${block_id}/children`,
        {
          method: "PATCH",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
            "Notion-Version": "2026-03-11",
          },
          body: JSON.stringify(body),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 3 days ago