0

List Comments

by
Published today

List the open (unresolved) comments on a page or block.

Script notion Verified

The script

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

3
/**
4
 * List Comments
5
 * List the open (unresolved) comments on a page or block. Pass a page ID for page-level comments. Paginate with `next_cursor` as `start_cursor`. Needs the read comments capability.
6
 */
7
export async function main(
8
  auth: RT.Notion,
9
  block_id: string,
10
  start_cursor: string | undefined,
11
  page_size: number | undefined
12
) {
13
  const url = new URL("https://api.notion.com/v1/comments")
14
  url.searchParams.append("block_id", block_id)
15
  if (start_cursor !== undefined && start_cursor !== "") {
16
    url.searchParams.append("start_cursor", start_cursor)
17
  }
18
  if (page_size !== undefined) {
19
    url.searchParams.append("page_size", String(page_size))
20
  }
21

22
  const response = await fetch(url, {
23
    headers: {
24
      Authorization: `Bearer ${auth.token}`,
25
      Accept: "application/json",
26
      "Notion-Version": "2026-03-11",
27
    },
28
  })
29

30
  if (!response.ok) {
31
    throw new Error(`${response.status} ${await response.text()}`)
32
  }
33

34
  return await response.json()
35
}
36