1 | |
2 | type Klaviyo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update Campaign |
7 | * Update a campaign with the given campaign ID.*Rate limits*:Burst: `10/s`Steady: `150/m` |
8 |
|
9 | */ |
10 | export async function main( |
11 | auth: Klaviyo, |
12 | id: string, |
13 | revision: string, |
14 | body: { |
15 | data: { |
16 | type: "campaign"; |
17 | id: string; |
18 | attributes: { |
19 | name?: string; |
20 | audiences?: { included?: string[]; excluded?: string[] }; |
21 | send_options?: { use_smart_sending?: false | true }; |
22 | tracking_options?: |
23 | | { |
24 | add_tracking_params?: false | true; |
25 | custom_tracking_params?: |
26 | | { |
27 | type: "dynamic"; |
28 | value: |
29 | | "campaign_id" |
30 | | "campaign_name" |
31 | | "campaign_name_id" |
32 | | "campaign_name_send_day" |
33 | | "email_subject" |
34 | | "group_id" |
35 | | "group_name" |
36 | | "group_name_id" |
37 | | "link_alt_text" |
38 | | "message_type" |
39 | | "profile_external_id" |
40 | | "profile_id"; |
41 | name: string; |
42 | } |
43 | | { type: "static"; value: string; name: string }[]; |
44 | is_tracking_clicks?: false | true; |
45 | is_tracking_opens?: false | true; |
46 | } |
47 | | { |
48 | add_tracking_params?: false | true; |
49 | custom_tracking_params?: |
50 | | { |
51 | type: "dynamic"; |
52 | value: |
53 | | "campaign_id" |
54 | | "campaign_name" |
55 | | "campaign_name_id" |
56 | | "campaign_name_send_day" |
57 | | "email_subject" |
58 | | "group_id" |
59 | | "group_name" |
60 | | "group_name_id" |
61 | | "link_alt_text" |
62 | | "message_type" |
63 | | "profile_external_id" |
64 | | "profile_id"; |
65 | name: string; |
66 | } |
67 | | { type: "static"; value: string; name: string }[]; |
68 | }; |
69 | send_strategy?: { |
70 | method: string; |
71 | options_static?: { |
72 | datetime: string; |
73 | is_local?: false | true; |
74 | send_past_recipients_immediately?: false | true; |
75 | }; |
76 | options_throttled?: { datetime: string; throttle_percentage: number }; |
77 | options_sto?: { date: string }; |
78 | }; |
79 | }; |
80 | }; |
81 | }, |
82 | ) { |
83 | const url = new URL(`https://a.klaviyo.com/api/campaigns/${id}`); |
84 |
|
85 | const response = await fetch(url, { |
86 | method: "PATCH", |
87 | headers: { |
88 | revision: revision, |
89 | "Accept": "application/vnd.api+json", |
90 | "Content-Type": "application/vnd.api+json", |
91 | Authorization: "Klaviyo-API-Key " + auth.apiKey, |
92 | }, |
93 | body: JSON.stringify(body), |
94 | }); |
95 | if (!response.ok) { |
96 | const text = await response.text(); |
97 | throw new Error(`${response.status} ${text}`); |
98 | } |
99 | return await response.json(); |
100 | } |
101 |
|