0

Update Flow Status

by
Published Apr 8, 2025

Update the status of a flow with the given flow ID, and all actions in that flow.*Rate limits*:Burst: `3/s`Steady: `60/m` **Scopes:** `flows: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
 * Update Flow Status
7
 * Update the status of a flow with the given flow ID, and all actions in that flow.*Rate limits*:Burst: `3/s`Steady: `60/m`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  id: string,
13
  revision: string,
14
  body: { data: { type: "flow"; id: string; attributes: { status: string } } },
15
) {
16
  const url = new URL(`https://a.klaviyo.com/api/flows/${id}`);
17

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