0

List all the sites with ads configured

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