Edits history of script submission #15958 for ' Create a site redirect (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Create a site redirect
     *
     */
    export async function main(
      auth: Gitbook,
      organizationId: string,
      siteId: string,
      body: {
        source: string;
        destination:
          | { kind: "site-section"; siteSectionId: string }
          | { kind: "site-space"; siteSpaceId: string }
          | { kind: "site-page"; siteSpaceId: string; pageId: string };
      },
    ) {
      const url = new URL(
        `https://api.gitbook.com/v1/orgs/${organizationId}/sites/${siteId}/redirects`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "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.json();
    }
    

    Submitted by hugo697 235 days ago