Edits history of script submission #12991 for ' Create access token (speechify)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Speechify = {
      token: string;
    };
    /**
     * Create access token
     * Create a new API token for the logged in user
     */
    export async function main(
      auth: Speechify,
      body: {
        grant_type: "client_credentials";
        scope?:
          | "audio:speech"
          | "audio:stream"
          | "audio:all"
          | "voices:read"
          | "voices:create"
          | "voices:delete"
          | "voices:all";
      },
    ) {
      const url = new URL(`https://api.sws.speechify.com/v1/auth/token`);
    
      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.text();
    }
    

    Submitted by hugo697 428 days ago