0

Update Template

by
Published Apr 8, 2025

Update a template with the given template ID. Does not currently update drag & drop templates.*Rate limits*:Burst: `10/s`Steady: `150/m` **Scopes:** `templates:write`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Update Template
7
 * Update a template with the given template ID. Does not currently update drag & drop templates.*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";
17
      id: string;
18
      attributes: { name?: string; html?: string; text?: string };
19
    };
20
  },
21
) {
22
  const url = new URL(`https://a.klaviyo.com/api/templates/${id}`);
23

24
  const response = await fetch(url, {
25
    method: "PATCH",
26
    headers: {
27
      revision: revision,
28
      "Accept": "application/vnd.api+json",
29
      "Content-Type": "application/vnd.api+json",
30
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40