0

License audio tracks

by
Published Oct 17, 2025

This endpoint gets licenses for one or more tracks. The download links in the response are valid for 8 hours.

Script shutterstock Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Shutterstock = {
3
  token: string;
4
};
5
/**
6
 * License audio tracks
7
 * This endpoint gets licenses for one or more tracks. The download links in the response are valid for 8 hours.
8
 */
9
export async function main(
10
  auth: Shutterstock,
11
  license:
12
    | "audio_platform"
13
    | "premier_music_basic"
14
    | "premier_music_extended"
15
    | "premier_music_pro"
16
    | "premier_music_comp"
17
    | "asset_all_music"
18
    | undefined,
19
  search_id: string | undefined,
20
  body: {
21
    audio: {
22
      audio_id: string;
23
      license?:
24
        | "audio_platform"
25
        | "premier_music_basic"
26
        | "premier_music_extended"
27
        | "premier_music_pro"
28
        | "premier_music_comp"
29
        | "asset_all_music";
30
      search_id?: string;
31
    }[];
32
  },
33
) {
34
  const url = new URL(`https://api.shutterstock.com/v2/audio/licenses`);
35
  for (const [k, v] of [
36
    ["license", license],
37
    ["search_id", search_id],
38
  ]) {
39
    if (v !== undefined && v !== "" && k !== undefined) {
40
      url.searchParams.append(k, v);
41
    }
42
  }
43
  const response = await fetch(url, {
44
    method: "POST",
45
    headers: {
46
      "Content-Type": "application/json",
47
      Authorization: "Bearer " + auth.token,
48
    },
49
    body: JSON.stringify(body),
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57