1 | |
2 | type Pinterest = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get product group promotions |
7 | * List existing product group promotions associated with an ad account. |
8 |
|
9 | Include either ad_group_id or product_group_promotion_ids in your request. |
10 |
|
11 | Note: ad_group_ids and product_group_promotion_ids are mutually exclusive parameters. |
12 | Only provide one. If multiple options are provided, product_group_promotion_ids takes precedence over ad_group_ids. If none are provided, the endpoint returns an error. |
13 | */ |
14 | export async function main( |
15 | auth: Pinterest, |
16 | ad_account_id: string, |
17 | product_group_promotion_ids: string | undefined, |
18 | entity_statuses: string | undefined, |
19 | ad_group_id: string | undefined, |
20 | page_size: string | undefined, |
21 | order: "ASCENDING" | "DESCENDING" | undefined, |
22 | bookmark: string | undefined, |
23 | ) { |
24 | const url = new URL( |
25 | `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/product_group_promotions`, |
26 | ); |
27 | for (const [k, v] of [ |
28 | ["product_group_promotion_ids", product_group_promotion_ids], |
29 | ["entity_statuses", entity_statuses], |
30 | ["ad_group_id", ad_group_id], |
31 | ["page_size", page_size], |
32 | ["order", order], |
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 |
|