1 | |
2 | type Pinterest = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update product group promotions |
7 | * Update multiple existing Product Group Promotions (by product_group_id) |
8 | */ |
9 | export async function main( |
10 | auth: Pinterest, |
11 | ad_account_id: string, |
12 | body: { |
13 | ad_group_id: string; |
14 | product_group_promotion: { |
15 | id?: string; |
16 | ad_group_id?: string; |
17 | bid_in_micro_currency?: number; |
18 | included?: false | true; |
19 | definition?: string; |
20 | relative_definition?: string; |
21 | parent_id?: string; |
22 | slideshow_collections_title?: string; |
23 | slideshow_collections_description?: string; |
24 | is_mdl?: false | true; |
25 | status?: "ACTIVE" | "PAUSED" | "ARCHIVED" | "DRAFT" | "DELETED_DRAFT"; |
26 | tracking_url?: string; |
27 | catalog_product_group_id?: string; |
28 | catalog_product_group_name?: string; |
29 | collections_hero_pin_id?: string; |
30 | collections_hero_destination_url?: string; |
31 | grid_click_type?: "CLOSEUP" | "DIRECT_TO_DESTINATION"; |
32 | }[]; |
33 | }, |
34 | ) { |
35 | const url = new URL( |
36 | `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/product_group_promotions`, |
37 | ); |
38 |
|
39 | const response = await fetch(url, { |
40 | method: "PATCH", |
41 | headers: { |
42 | "Content-Type": "application/json", |
43 | Authorization: "Bearer " + auth.token, |
44 | }, |
45 | body: JSON.stringify(body), |
46 | }); |
47 | if (!response.ok) { |
48 | const text = await response.text(); |
49 | throw new Error(`${response.status} ${text}`); |
50 | } |
51 | return await response.json(); |
52 | } |
53 |
|