0

Get Messages for Flow Action

by
Published Apr 8, 2025

Get all flow messages associated with the given action ID. Flow messages can be sorted by the following fields, in ascending and descending order: ascending: `id`, `name`, `created`, `updated` descending: `-id`, `-name`, `-created`, `-updated` Returns a maximum of 50 flows per request, which can be paginated with offset pagination. Offset pagination uses the following parameters: `page[size]` and `page[number]`*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 Messages for Flow Action
7
 * Get all flow messages associated with the given action ID.
8

9
Flow messages can be sorted by the following fields, in ascending and descending order:
10

11
ascending: `id`,  `name`, `created`, `updated`
12
descending: `-id`,  `-name`, `-created`, `-updated`
13

14
Returns a maximum of 50 flows per request, which can be paginated with offset pagination. Offset pagination uses the following parameters: `page[size]` and `page[number]`*Rate limits*:Burst: `3/s`Steady: `60/m`
15

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