1 | |
2 | type Bitly = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Retrieve QR Codes by Group |
7 | * Retrieves a list of QR codes matching the filter settings. Values are in reverse chronological order. |
8 | The pagination occurs by calling the next link in the pagination response object. |
9 |
|
10 | */ |
11 | export async function main( |
12 | auth: Bitly, |
13 | group_guid: string, |
14 | has_render_customizations: "on" | "off" | "both" | undefined, |
15 | archived: "on" | "off" | "both" | undefined, |
16 | size: string | undefined, |
17 | search_after: string | undefined, |
18 | ) { |
19 | const url = new URL( |
20 | `https://api-ssl.bitly.com/v4/groups/${group_guid}/qr-codes`, |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["has_render_customizations", has_render_customizations], |
24 | ["archived", archived], |
25 | ["size", size], |
26 | ["search_after", search_after], |
27 | ]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "GET", |
34 | headers: { |
35 | Authorization: "Bearer " + auth.token, |
36 | }, |
37 | body: undefined, |
38 | }); |
39 | if (!response.ok) { |
40 | const text = await response.text(); |
41 | throw new Error(`${response.status} ${text}`); |
42 | } |
43 | return await response.json(); |
44 | } |
45 |
|