//native
type Klaviyo = {
apiKey: string;
};
/**
* Query Segment Values
* Returns the requested segment analytics values data.*Rate limits*:Burst: `1/s`Steady: `2/m`Daily: `225/d`
*/
export async function main(
auth: Klaviyo,
revision: string,
body: {
data: {
type: "segment-values-report";
attributes: {
statistics:
| "members_added"
| "members_removed"
| "net_members_changed"
| "total_members"[];
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 };
filter?: string;
};
};
},
) {
const url = new URL(`https://a.klaviyo.com/api/segment-values-reports`);
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