0

Get Message IDs for Flow Action

by
Published Apr 8, 2025

Get all relationships for flow messages associated with the given flow action ID. Returns a maximum of 50 flow message relationships per request, which can be paginated with cursor-based pagination.*Rate limits*:Burst: `3/s`Steady: `60/m` **Scopes:** `flows: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 Message IDs for Flow Action
7
 * Get all relationships for flow messages associated with the given flow action ID.
8

9
Returns a maximum of 50 flow message relationships per request, which can be paginated with cursor-based pagination.*Rate limits*:Burst: `3/s`Steady: `60/m`
10

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