//native
type Klaviyo = {
apiKey: string;
};
/**
* Query Flow Series
* Returns the requested flow analytics series data*Rate limits*:Burst: `1/s`Steady: `2/m`Daily: `225/d`
*/
export async function main(
auth: Klaviyo,
page_cursor: string | undefined,
revision: string,
body: {
data: {
type: "flow-series-report";
attributes: {
statistics:
| "average_order_value"
| "bounce_rate"
| "bounced"
| "bounced_or_failed"
| "bounced_or_failed_rate"
| "click_rate"
| "click_to_open_rate"
| "clicks"
| "clicks_unique"
| "conversion_rate"
| "conversion_uniques"
| "conversion_value"
| "conversions"
| "delivered"
| "delivery_rate"
| "failed"
| "failed_rate"
| "open_rate"
| "opens"
| "opens_unique"
| "recipients"
| "revenue_per_recipient"
| "spam_complaint_rate"
| "spam_complaints"
| "unsubscribe_rate"
| "unsubscribe_uniques"
| "unsubscribes"[];
timeframe:
| {
key:
| "last_12_months"
| "last_30_days"
| "last_365_days"
| "last_3_months"
| "last_7_days"
| "last_90_days"
| "last_month"
| "last_week"
| "last_year"
| "this_month"
| "this_week"
| "this_year"
| "today"
| "yesterday";
}
| { start: string; end: string };
interval: "daily" | "hourly" | "monthly" | "weekly";
conversion_metric_id: string;
filter?: string;
};
};
},
) {
const url = new URL(`https://a.klaviyo.com/api/flow-series-reports`);
for (const [k, v] of [["page_cursor", page_cursor]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
revision: revision,
"Accept": "application/vnd.api+json",
"Content-Type": "application/vnd.api+json",
Authorization: "Klaviyo-API-Key " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago