0

Create Tag Group

by
Published Apr 8, 2025

Create a tag group. An account cannot have more than **50** unique tag groups. If `exclusive` is not specified `true` or `false`, the tag group defaults to non-exclusive. If a tag group is non-exclusive, any given related resource (campaign, flow, etc.) can be linked to multiple tags from that tag group. If a tag group is exclusive, any given related resource can only be linked to one tag from that tag group.*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
 * Create Tag Group
7
 * Create a tag group. An account cannot have more than **50** unique tag groups.
8

9
If `exclusive` is not specified `true` or `false`, the tag group defaults to non-exclusive.
10

11
If a tag group is non-exclusive, any given related resource (campaign, flow, etc.)
12
can be linked to multiple tags from that tag group.
13
If a tag group is exclusive, any given related resource can only be linked to one tag from that tag group.*Rate limits*:Burst: `3/s`Steady: `60/m`
14

15
 */
16
export async function main(
17
  auth: Klaviyo,
18
  revision: string,
19
  body: {
20
    data: {
21
      type: "tag-group";
22
      attributes: { name: string; exclusive?: false | true };
23
    };
24
  },
25
) {
26
  const url = new URL(`https://a.klaviyo.com/api/tag-groups`);
27

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