0

Update Tag Group

by
Published Apr 8, 2025

Update the tag group with the given tag group ID. Only a tag group's `name` can be changed. A tag group's `exclusive` or `default` value cannot be changed.*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 Group
7
 * Update the tag group with the given tag group ID.
8

9
Only a tag group's `name` can be changed. A tag group's `exclusive` or `default` value cannot be changed.*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: {
17
    data: {
18
      type: "tag-group";
19
      id: string;
20
      attributes: { name: string; return_fields?: string[] };
21
    };
22
  },
23
) {
24
  const url = new URL(`https://a.klaviyo.com/api/tag-groups/${id}`);
25

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