//native
type Klaviyo = {
apiKey: string;
};
/**
* Get Variant IDs for Catalog Item
* Get all variants related to the given item ID.
Variants can be sorted by the following fields, in ascending and descending order:
`created`
Returns a maximum of 100 variants per request.*Rate limits*:Burst: `350/s`Steady: `3500/m`
*/
export async function main(
auth: Klaviyo,
id: string,
filter: string | undefined,
page_cursor_: string | undefined,
sort: "created" | "-created" | undefined,
revision: string,
) {
const url = new URL(
`https://a.klaviyo.com/api/catalog-items/${id}/relationships/variants`,
);
for (const [k, v] of [
["filter", filter],
["page[cursor]", page_cursor_],
["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