Edits history of script submission #16224 for ' Update the Ads configuration for a site (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Update the Ads configuration for a site
     *
     */
    export async function main(
      auth: Gitbook,
      siteId: string,
      X_GitBook_Partner_Key: string,
      body:
        | { status: "live"; zoneId: string; reportingId: string }
        | { status: "rejected"; reason?: string }
        | { status: "pending" },
    ) {
      const url = new URL(`https://api.gitbook.com/v1/ads/sites/${siteId}`);
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "X-GitBook-Partner-Key": X_GitBook_Partner_Key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago