//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