Edits history of script submission #15962 for ' Create an integration installation API token (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Create an integration installation API token
     * Creates a temporary API token of an integration's installation that has access to the installation and it's scopes. You must be authenticated as the integration to obtain this token.
    
     */
    export async function main(
      auth: Gitbook,
      integrationName: string,
      installationId: string,
    ) {
      const url = new URL(
        `https://api.gitbook.com/v1/integrations/${integrationName}/installations/${installationId}/tokens`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago