0

Retrieve Block

by
Published Jun 6, 2022

Get a single block by ID.

Script notion Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 3 days ago
1
//native
2

3
/**
4
 * Retrieve Block
5
 * Get a single block by ID. A page ID also works, returning the page as a child_page block.
6
 */
7
export async function main(auth: RT.Notion, block_id: string) {
8
  const response = await fetch(`https://api.notion.com/v1/blocks/${block_id}`, {
9
    headers: {
10
      Authorization: `Bearer ${auth.token}`,
11
      Accept: "application/json",
12
      "Notion-Version": "2026-03-11",
13
    },
14
  })
15

16
  if (!response.ok) {
17
    throw new Error(`${response.status} ${await response.text()}`)
18
  }
19

20
  return await response.json()
21
}
22

Other submissions
  • Submitted by adam186 Deno
    Created 516 days ago
    1
    import { Client } from "npm:@notionhq/client";
    2
    
    
    3
    /**
    4
     * Learn more at
    5
     * https://developers.notion.com/reference/retrieve-a-block
    6
     */
    7
    type Notion = {
    8
      token: string;
    9
    };
    10
    export async function main(auth: Notion, block_id: string) {
    11
      const client = new Client({ auth: auth.token });
    12
      return await client.blocks.retrieve({ block_id });
    13
    }
    14
    
    
  • Submitted by hugo989 Bun
    Created 124 days ago
    1
    import { Client } from "@notionhq/client";
    2
    
    
    3
    /**
    4
     * Learn more at
    5
     * https://developers.notion.com/reference/retrieve-a-block
    6
     */
    7
    type Notion = {
    8
      token: string;
    9
    };
    10
    export async function main(auth: Notion, block_id: string) {
    11
      const client = new Client({ auth: auth.token });
    12
      return await client.blocks.retrieve({ block_id });
    13
    }
    14