1 | |
2 | type Pinterest = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create product group promotions |
7 | * Add one or more product groups from your catalog to an existing ad group. (Product groups added to an ad group are a 'product group promotion.') |
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 | creative_type?: |
34 | | "REGULAR" |
35 | | "VIDEO" |
36 | | "SHOPPING" |
37 | | "CAROUSEL" |
38 | | "MAX_VIDEO" |
39 | | "SHOP_THE_PIN" |
40 | | "COLLECTION" |
41 | | "IDEA" |
42 | | "SHOWCASE" |
43 | | "QUIZ"; |
44 | }[]; |
45 | }, |
46 | ) { |
47 | const url = new URL( |
48 | `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/product_group_promotions`, |
49 | ); |
50 |
|
51 | const response = await fetch(url, { |
52 | method: "POST", |
53 | headers: { |
54 | "Content-Type": "application/json", |
55 | Authorization: "Bearer " + auth.token, |
56 | }, |
57 | body: JSON.stringify(body), |
58 | }); |
59 | if (!response.ok) { |
60 | const text = await response.text(); |
61 | throw new Error(`${response.status} ${text}`); |
62 | } |
63 | return await response.json(); |
64 | } |
65 |
|