0

List conversations issues clusters

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 conversations issues clusters
7
 *
8
 */
9
export async function main(
10
  auth: Gitbook,
11
  organizationId: string,
12
  page: string | undefined,
13
  limit: string | undefined,
14
  order: "asc" | "desc" | undefined,
15
  orderBy:
16
    | "updatedAt"
17
    | "issues"
18
    | "conversations"
19
    | "tasksTotal"
20
    | "tasksBacklog"
21
    | "tasksStarted"
22
    | undefined,
23
  status: "pending" | "analysing" | undefined,
24
) {
25
  const url = new URL(
26
    `https://api.gitbook.com/v1/orgs/${organizationId}/conversations-clusters`,
27
  );
28
  for (const [k, v] of [
29
    ["page", page],
30
    ["limit", limit],
31
    ["order", order],
32
    ["orderBy", orderBy],
33
    ["status", status],
34
  ]) {
35
    if (v !== undefined && v !== "" && k !== undefined) {
36
      url.searchParams.append(k, v);
37
    }
38
  }
39
  const response = await fetch(url, {
40
    method: "GET",
41
    headers: {
42
      Authorization: "Bearer " + auth.token,
43
    },
44
    body: undefined,
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.json();
51
}
52