1 | |
2 | type Klaviyo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update Universal Content |
7 | * Update universal content. The `definition` field can only be updated for text blocks at this time.*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: "template-universal-content"; |
17 | id: string; |
18 | attributes: { |
19 | name?: string; |
20 | definition?: |
21 | | { |
22 | content_type: "block"; |
23 | type: "html"; |
24 | data: { |
25 | content: string; |
26 | display_options: { |
27 | show_on?: "all" | "desktop" | "mobile"; |
28 | visible_check?: string; |
29 | content_repeat?: { repeat_for: string; item_alias: string }; |
30 | }; |
31 | }; |
32 | } |
33 | | { |
34 | content_type: "block"; |
35 | type: "text"; |
36 | data: { |
37 | content: string; |
38 | display_options: { |
39 | show_on?: "all" | "desktop" | "mobile"; |
40 | visible_check?: string; |
41 | content_repeat?: { repeat_for: string; item_alias: string }; |
42 | }; |
43 | styles: { |
44 | block_background_color?: string; |
45 | block_border_color?: string; |
46 | block_border_style?: |
47 | | "dashed" |
48 | | "dotted" |
49 | | "groove" |
50 | | "inset" |
51 | | "none" |
52 | | "outset" |
53 | | "ridge" |
54 | | "solid"; |
55 | block_border_width?: number; |
56 | block_padding_bottom?: number; |
57 | block_padding_left?: number; |
58 | block_padding_right?: number; |
59 | block_padding_top?: number; |
60 | color?: string; |
61 | extra_css_class?: string; |
62 | font_family?: string; |
63 | font_size?: number; |
64 | font_style?: "italic" | "normal"; |
65 | font_weight?: string; |
66 | inner_padding_bottom?: number; |
67 | inner_padding_left?: number; |
68 | inner_padding_right?: number; |
69 | inner_padding_top?: number; |
70 | mobile_stretch_content?: false | true; |
71 | background_color?: string; |
72 | letter_spacing?: number; |
73 | line_height?: number; |
74 | text_align?: "center" | "left" | "right"; |
75 | text_decoration?: string; |
76 | text_table_layout?: "auto" | "fixed" | "inherit" | "initial"; |
77 | }; |
78 | }; |
79 | }; |
80 | }; |
81 | }; |
82 | }, |
83 | ) { |
84 | const url = new URL( |
85 | `https://a.klaviyo.com/api/template-universal-content/${id}`, |
86 | ); |
87 |
|
88 | const response = await fetch(url, { |
89 | method: "PATCH", |
90 | headers: { |
91 | revision: revision, |
92 | "Accept": "application/vnd.api+json", |
93 | "Content-Type": "application/vnd.api+json", |
94 | Authorization: "Klaviyo-API-Key " + auth.apiKey, |
95 | }, |
96 | body: JSON.stringify(body), |
97 | }); |
98 | if (!response.ok) { |
99 | const text = await response.text(); |
100 | throw new Error(`${response.status} ${text}`); |
101 | } |
102 | return await response.json(); |
103 | } |
104 |
|