0

Create Campaign Clone

by
Published Apr 8, 2025

Clones an existing campaign, returning a new campaign based on the original with a new ID and name.*Rate limits*:Burst: `10/s`Steady: `150/m` **Scopes:** `campaigns: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
 * Create Campaign Clone
7
 * Clones an existing campaign, returning a new campaign based on the original with a new ID and name.*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: { type: "campaign"; id: string; attributes: { new_name?: string } };
15
  },
16
) {
17
  const url = new URL(`https://a.klaviyo.com/api/campaign-clone`);
18

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