1 | |
2 | type Pinterest = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get assets assigned to a member |
7 | * Get assets on which you assigned asset permissions to the given member. Can be used to: |
8 | - get all assets, regardless of asset type or |
9 | - get assets of one asset type by using the asset_type query. |
10 | The return response will include the permissions the member has to that asset and the asset type. |
11 | */ |
12 | export async function main( |
13 | auth: Pinterest, |
14 | business_id: string, |
15 | member_id: string, |
16 | asset_type: "AD_ACCOUNT" | "PROFILE" | "ASSET_GROUP" | undefined, |
17 | start_index: string | undefined, |
18 | bookmark: string | undefined, |
19 | page_size: string | undefined, |
20 | ) { |
21 | const url = new URL( |
22 | `https://api.pinterest.com/v5/businesses/${business_id}/members/${member_id}/assets`, |
23 | ); |
24 | for (const [k, v] of [ |
25 | ["asset_type", asset_type], |
26 | ["start_index", start_index], |
27 | ["bookmark", bookmark], |
28 | ["page_size", page_size], |
29 | ]) { |
30 | if (v !== undefined && v !== "" && k !== undefined) { |
31 | url.searchParams.append(k, v); |
32 | } |
33 | } |
34 | const response = await fetch(url, { |
35 | method: "GET", |
36 | headers: { |
37 | Authorization: "Bearer " + auth.token, |
38 | }, |
39 | body: undefined, |
40 | }); |
41 | if (!response.ok) { |
42 | const text = await response.text(); |
43 | throw new Error(`${response.status} ${text}`); |
44 | } |
45 | return await response.json(); |
46 | } |
47 |
|