1 | |
2 | type Pinterest = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get business members |
7 | * Get all members of the specified business. |
8 | The return response will include the member's business_role and assets they have access to if assets_summary=TRUE |
9 | */ |
10 | export async function main( |
11 | auth: Pinterest, |
12 | business_id: string, |
13 | assets_summary: string | undefined, |
14 | business_roles: string | undefined, |
15 | member_ids: string | 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}/members`, |
22 | ); |
23 | for (const [k, v] of [ |
24 | ["assets_summary", assets_summary], |
25 | ["business_roles", business_roles], |
26 | ["member_ids", member_ids], |
27 | ["start_index", start_index], |
28 | ["bookmark", bookmark], |
29 | ["page_size", page_size], |
30 | ]) { |
31 | if (v !== undefined && v !== "" && k !== undefined) { |
32 | url.searchParams.append(k, v); |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: "GET", |
37 | headers: { |
38 | Authorization: "Bearer " + auth.token, |
39 | }, |
40 | body: undefined, |
41 | }); |
42 | if (!response.ok) { |
43 | const text = await response.text(); |
44 | throw new Error(`${response.status} ${text}`); |
45 | } |
46 | return await response.json(); |
47 | } |
48 |
|