Edits history of script submission #16222 for ' Update glossary entries (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Update glossary entries
     *
     */
    export async function main(
      auth: Gitbook,
      organizationId: string,
      body: {
        operations:
          | { type: "insert"; translations: {} }
          | { type: "update"; id: string; translations: {} }
          | { type: "delete"; id: string }[];
      },
    ) {
      const url = new URL(
        `https://api.gitbook.com/v1/orgs/${organizationId}/translations-glossary`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        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.text();
    }
    

    Submitted by hugo697 235 days ago