0

Clone Template

by
Published Apr 8, 2025

Create a clone of a template with the given template ID. If there are 1,000 or more templates in an account, cloning will fail as there is a limit of 1,000 templates that can be created via the API.*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
 * Clone Template
7
 * Create a clone of a template with the given template ID.
8

9
If there are 1,000 or more templates in an account, cloning will fail as there is a limit of 1,000 templates
10
that can be created via the API.*Rate limits*:Burst: `10/s`Steady: `150/m`
11

12
 */
13
export async function main(
14
  auth: Klaviyo,
15
  revision: string,
16
  body: {
17
    data: { type: "template"; id: string; attributes: { name?: string } };
18
  },
19
) {
20
  const url = new URL(`https://a.klaviyo.com/api/template-clone`);
21

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