0

List all space comments

by
Published Oct 17, 2025
Script gitbook Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Gitbook = {
3
  token: string;
4
};
5
/**
6
 * List all space comments
7
 *
8
 */
9
export async function main(
10
  auth: Gitbook,
11
  spaceId: string,
12
  page: string | undefined,
13
  limit: string | undefined,
14
  order: "asc" | "desc" | undefined,
15
  status: "all" | "open" | "resolved" | undefined,
16
  format: "document" | "markdown" | undefined,
17
  targetPage: string | undefined,
18
  authors: string | undefined,
19
) {
20
  const url = new URL(`https://api.gitbook.com/v1/spaces/${spaceId}/comments`);
21
  for (const [k, v] of [
22
    ["page", page],
23
    ["limit", limit],
24
    ["order", order],
25
    ["status", status],
26
    ["format", format],
27
    ["targetPage", targetPage],
28
    ["authors", authors],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47