1 | |
2 | type Pinterest = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create campaigns |
7 | * Create multiple new campaigns. |
8 | */ |
9 | export async function main( |
10 | auth: Pinterest, |
11 | ad_account_id: string, |
12 | body: { |
13 | ad_account_id?: string; |
14 | name?: string; |
15 | status?: "ACTIVE" | "PAUSED" | "ARCHIVED" | "DRAFT" | "DELETED_DRAFT"; |
16 | lifetime_spend_cap?: number; |
17 | daily_spend_cap?: number; |
18 | order_line_id?: string; |
19 | tracking_urls?: { |
20 | impression?: string[]; |
21 | click?: string[]; |
22 | engagement?: string[]; |
23 | buyable_button?: string[]; |
24 | audience_verification?: string[]; |
25 | }; |
26 | start_time?: number; |
27 | end_time?: number; |
28 | is_flexible_daily_budgets?: false | true; |
29 | } & { |
30 | default_ad_group_budget_in_micro_currency?: number; |
31 | is_automated_campaign?: false | true; |
32 | } & { |
33 | is_flexible_daily_budgets?: false | true; |
34 | is_automated_campaign?: false | true; |
35 | status?: "ACTIVE" | "PAUSED" | "ARCHIVED" | "DRAFT" | "DELETED_DRAFT"; |
36 | objective_type: |
37 | | "AWARENESS" |
38 | | "CONSIDERATION" |
39 | | "VIDEO_VIEW" |
40 | | "WEB_CONVERSION" |
41 | | "CATALOG_SALES" |
42 | | "WEB_SESSIONS" |
43 | | "VIDEO_COMPLETION"; |
44 | }[], |
45 | ) { |
46 | const url = new URL( |
47 | `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/campaigns`, |
48 | ); |
49 |
|
50 | const response = await fetch(url, { |
51 | method: "POST", |
52 | headers: { |
53 | "Content-Type": "application/json", |
54 | Authorization: "Bearer " + auth.token, |
55 | }, |
56 | body: JSON.stringify(body), |
57 | }); |
58 | if (!response.ok) { |
59 | const text = await response.text(); |
60 | throw new Error(`${response.status} ${text}`); |
61 | } |
62 | return await response.json(); |
63 | } |
64 |
|