1 | |
2 | type Pinterest = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List business assets |
7 | * Get all the assets the requesting business has access to. This includes assets the business owns and assets the business has access to through partnerships. |
8 | */ |
9 | export async function main( |
10 | auth: Pinterest, |
11 | business_id: string, |
12 | permissions: string | undefined, |
13 | child_asset_id: string | undefined, |
14 | asset_group_id: string | undefined, |
15 | asset_type: "AD_ACCOUNT" | "PROFILE" | "ASSET_GROUP" | undefined, |
16 | start_index: string | undefined, |
17 | bookmark: string | undefined, |
18 | page_size: string | undefined, |
19 | ) { |
20 | const url = new URL( |
21 | `https://api.pinterest.com/v5/businesses/${business_id}/assets`, |
22 | ); |
23 | for (const [k, v] of [ |
24 | ["permissions", permissions], |
25 | ["child_asset_id", child_asset_id], |
26 | ["asset_group_id", asset_group_id], |
27 | ["asset_type", asset_type], |
28 | ["start_index", start_index], |
29 | ["bookmark", bookmark], |
30 | ["page_size", page_size], |
31 | ]) { |
32 | if (v !== undefined && v !== "" && k !== undefined) { |
33 | url.searchParams.append(k, v); |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: "GET", |
38 | headers: { |
39 | Authorization: "Bearer " + auth.token, |
40 | }, |
41 | body: undefined, |
42 | }); |
43 | if (!response.ok) { |
44 | const text = await response.text(); |
45 | throw new Error(`${response.status} ${text}`); |
46 | } |
47 | return await response.json(); |
48 | } |
49 |
|