Edits history of script submission #15963 for ' Create an organization invite (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Create an organization invite
     *
     */
    export async function main(
      auth: Gitbook,
      organizationId: string,
      body:
        | { role: "admin" | "create" | "edit" | "review" | "comment" | "read" }
        | {
            level: "admin" | "create" | "edit" | "review" | "comment" | "read";
            space: string;
          }
        | {
            level: "admin" | "create" | "edit" | "review" | "comment" | "read";
            collection: string;
          },
    ) {
      const url = new URL(`https://api.gitbook.com/v1/orgs/${organizationId}/link-invites`);
    
      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