Edits history of script submission #20349 for ' Get access tokens (shutterstock)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Shutterstock = {
      token: string;
    };
    /**
     * Get access tokens
     * This endpoint returns an access token for the specified user and with the specified scopes. The token does not expire until the user changes their password. The body parameters must be encoded as form data.
     */
    export async function main(
      auth: Shutterstock,
      body: {
        client_id: string;
        client_secret?: string;
        code?: string;
        grant_type: "authorization_code" | "client_credentials" | "refresh_token";
        realm?: "customer" | "contributor";
        expires?: false | true;
        refresh_token?: string;
      },
    ) {
      const url = new URL(`https://api.shutterstock.com/v2/oauth/access_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.json();
    }
    

    Submitted by hugo697 235 days ago