0

List all change request 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 change request comments
7
 *
8
 */
9
export async function main(
10
  auth: Gitbook,
11
  spaceId: string,
12
  changeRequestId: string,
13
  page: string | undefined,
14
  limit: string | undefined,
15
  order: "asc" | "desc" | undefined,
16
  format: "document" | "markdown" | undefined,
17
  status: "all" | "open" | "resolved" | undefined,
18
  targetPage: string | undefined,
19
  authors: string | undefined,
20
) {
21
  const url = new URL(
22
    `https://api.gitbook.com/v1/spaces/${spaceId}/change-requests/${changeRequestId}/comments`,
23
  );
24
  for (const [k, v] of [
25
    ["page", page],
26
    ["limit", limit],
27
    ["order", order],
28
    ["format", format],
29
    ["status", status],
30
    ["targetPage", targetPage],
31
    ["authors", authors],
32
  ]) {
33
    if (v !== undefined && v !== "" && k !== undefined) {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "GET",
39
    headers: {
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: undefined,
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50