0

Cancel Campaign Send

by
Published Apr 8, 2025

Permanently cancel the campaign, setting the status to CANCELED or revert the campaign, setting the status back to DRAFT*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
 * Cancel Campaign Send
7
 * Permanently cancel the campaign, setting the status to CANCELED or
8
revert the campaign, setting the status back to DRAFT*Rate limits*:Burst: `10/s`Steady: `150/m`
9

10
 */
11
export async function main(
12
  auth: Klaviyo,
13
  id: string,
14
  revision: string,
15
  body: {
16
    data: {
17
      type: "campaign-send-job";
18
      id: string;
19
      attributes: { action: "cancel" | "revert" };
20
    };
21
  },
22
) {
23
  const url = new URL(`https://a.klaviyo.com/api/campaign-send-jobs/${id}`);
24

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