0

Get Action IDs for Flow

by
Published Apr 8, 2025

Get all [relationships](https://developers.

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 Action IDs for Flow
7
 * Get all [relationships](https://developers.
8
 */
9
export async function main(
10
  auth: Klaviyo,
11
  id: string,
12
  filter: string | undefined,
13
  page_size_: string | undefined,
14
  sort:
15
    | "created"
16
    | "-created"
17
    | "id"
18
    | "-id"
19
    | "status"
20
    | "-status"
21
    | "updated"
22
    | "-updated"
23
    | undefined,
24
  revision: string,
25
) {
26
  const url = new URL(
27
    `https://a.klaviyo.com/api/flows/${id}/relationships/flow-actions`,
28
  );
29
  for (const [k, v] of [
30
    ["filter", filter],
31
    ["page[size]", page_size_],
32
    ["sort", sort],
33
  ]) {
34
    if (v !== undefined && v !== "" && k !== undefined) {
35
      url.searchParams.append(k, v);
36
    }
37
  }
38
  const response = await fetch(url, {
39
    method: "GET",
40
    headers: {
41
      revision: revision,
42
      "Accept": "application/vnd.api+json",
43
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
44
    },
45
    body: undefined,
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53