0

Tag Lists

by
Published Apr 8, 2025

Associate a tag with one or more lists. Any list cannot be associated with more than **100** tags. Use the request body to pass in the ID(s) of the lists(s) that will be associated with the tag.*Rate limits*:Burst: `3/s`Steady: `60/m` **Scopes:** `lists: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
 * Tag Lists
7
 * Associate a tag with one or more lists. Any list cannot be associated with more than **100** tags.
8

9

10
Use the request body to pass in the ID(s) of the lists(s) that will be associated with the tag.*Rate limits*:Burst: `3/s`Steady: `60/m`
11

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

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