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