0

List all sites

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