0

Get access tokens

by
Published Oct 17, 2025

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.

Script shutterstock Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Shutterstock = {
3
  token: string;
4
};
5
/**
6
 * Get access tokens
7
 * 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.
8
 */
9
export async function main(
10
  auth: Shutterstock,
11
  body: {
12
    client_id: string;
13
    client_secret?: string;
14
    code?: string;
15
    grant_type: "authorization_code" | "client_credentials" | "refresh_token";
16
    realm?: "customer" | "contributor";
17
    expires?: false | true;
18
    refresh_token?: string;
19
  },
20
) {
21
  const url = new URL(`https://api.shutterstock.com/v2/oauth/access_token`);
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "Content-Type": "application/json",
27
      Authorization: "Bearer " + auth.token,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37