1 | |
2 | type Pinterest = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get business partners |
7 | * Get all partners of the specified business. |
8 |
|
9 | If the assets_summary=TRUE and: |
10 | - partner_type=INTERNAL, the business assets returned are your business assets the partner has access to. |
11 | - partner_type=EXTERNAL, the business assets returned are your partner's business assets the partner has granted you |
12 | access to. |
13 | */ |
14 | export async function main( |
15 | auth: Pinterest, |
16 | business_id: string, |
17 | assets_summary: string | undefined, |
18 | partner_type: "INTERNAL" | "EXTERNAL" | undefined, |
19 | partner_ids: string | undefined, |
20 | start_index: string | undefined, |
21 | page_size: string | undefined, |
22 | bookmark: string | undefined, |
23 | ) { |
24 | const url = new URL( |
25 | `https://api.pinterest.com/v5/businesses/${business_id}/partners`, |
26 | ); |
27 | for (const [k, v] of [ |
28 | ["assets_summary", assets_summary], |
29 | ["partner_type", partner_type], |
30 | ["partner_ids", partner_ids], |
31 | ["start_index", start_index], |
32 | ["page_size", page_size], |
33 | ["bookmark", bookmark], |
34 | ]) { |
35 | if (v !== undefined && v !== "" && k !== undefined) { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "GET", |
41 | headers: { |
42 | Authorization: "Bearer " + auth.token, |
43 | }, |
44 | body: undefined, |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.json(); |
51 | } |
52 |
|