//native
type Klaviyo = {
apiKey: string;
};
/**
* Get Messages for Flow Action
* 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`
*/
export async function main(
auth: Klaviyo,
id: string,
fields_flow_message_: string | undefined,
filter: string | undefined,
page_size_: string | undefined,
sort:
| "created"
| "-created"
| "id"
| "-id"
| "name"
| "-name"
| "updated"
| "-updated"
| undefined,
revision: string,
) {
const url = new URL(
`https://a.klaviyo.com/api/flow-actions/${id}/flow-messages`,
);
for (const [k, v] of [
["fields[flow-message]", fields_flow_message_],
["filter", filter],
["page[size]", page_size_],
["sort", sort],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
revision: revision,
"Accept": "application/vnd.api+json",
Authorization: "Klaviyo-API-Key " + auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago