0

Get Tags for Flow

by
Published Apr 8, 2025

Return all tags associated with the given flow ID.*Rate limits*:Burst: `3/s`Steady: `60/m` **Scopes:** `flows:read` `tags:read`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Get Tags for Flow
7
 * Return all tags associated with the given flow ID.*Rate limits*:Burst: `3/s`Steady: `60/m`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  id: string,
13
  fields_tag_: string | undefined,
14
  revision: string,
15
) {
16
  const url = new URL(`https://a.klaviyo.com/api/flows/${id}/tags`);
17
  for (const [k, v] of [["fields[tag]", fields_tag_]]) {
18
    if (v !== undefined && v !== "" && k !== undefined) {
19
      url.searchParams.append(k, v);
20
    }
21
  }
22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      revision: revision,
26
      "Accept": "application/vnd.api+json",
27
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
28
    },
29
    body: undefined,
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37