0

Update Tag

by
Published Apr 8, 2025

Update the tag with the given tag ID. Only a tag's `name` can be changed. A tag cannot be moved from one tag group to another.*Rate limits*:Burst: `3/s`Steady: `60/m` **Scopes:** `tags:read` `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
 * Update Tag
7
 * Update the tag with the given tag ID.
8

9
Only a tag's `name` can be changed. A tag cannot be moved from one tag group to another.*Rate limits*:Burst: `3/s`Steady: `60/m`
10

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

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