0

Update the Ads configuration for a site

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
 * Update the Ads configuration for a site
7
 *
8
 */
9
export async function main(
10
  auth: Gitbook,
11
  siteId: string,
12
  X_GitBook_Partner_Key: string,
13
  body:
14
    | { status: "live"; zoneId: string; reportingId: string }
15
    | { status: "rejected"; reason?: string }
16
    | { status: "pending" },
17
) {
18
  const url = new URL(`https://api.gitbook.com/v1/ads/sites/${siteId}`);
19

20
  const response = await fetch(url, {
21
    method: "PATCH",
22
    headers: {
23
      "X-GitBook-Partner-Key": X_GitBook_Partner_Key,
24
      "Content-Type": "application/json",
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: JSON.stringify(body),
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.text();
34
}
35