0

Remove Tag from Campaigns

by
Published Apr 8, 2025

Remove a tag's association with one or more campaigns. Use the request body to pass in the ID(s) of the campaign(s) whose association with the tag will be removed.*Rate limits*:Burst: `3/s`Steady: `60/m` **Scopes:** `campaigns:write` `tags: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
 * Remove Tag from Campaigns
7
 * Remove a tag's association with one or more campaigns.
8

9

10
Use the request body to pass in the ID(s) of the campaign(s) whose association with the tag
11
will be removed.*Rate limits*:Burst: `3/s`Steady: `60/m`
12

13
 */
14
export async function main(
15
  auth: Klaviyo,
16
  id: string,
17
  revision: string,
18
  body: { data: { type: "campaign"; id: string }[] },
19
) {
20
  const url = new URL(
21
    `https://a.klaviyo.com/api/tags/${id}/relationships/campaigns`,
22
  );
23

24
  const response = await fetch(url, {
25
    method: "DELETE",
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