0

Get Catalog Variants

by
Published Apr 8, 2025

Get all variants in an account. Variants can be sorted by the following fields, in ascending and descending order: `created` Currently, the only supported integration type is `$custom`, and the only supported catalog type is `$default`. Returns a maximum of 100 variants per request.*Rate limits*:Burst: `350/s`Steady: `3500/m` **Scopes:** `catalogs:read`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Get Catalog Variants
7
 * Get all variants in an account.
8

9
Variants can be sorted by the following fields, in ascending and descending order:
10
`created`
11

12
Currently, the only supported integration type is `$custom`, and the only supported catalog type is `$default`.
13

14
Returns a maximum of 100 variants per request.*Rate limits*:Burst: `350/s`Steady: `3500/m`
15

16
 */
17
export async function main(
18
  auth: Klaviyo,
19
  fields_catalog_variant_: string | undefined,
20
  filter: string | undefined,
21
  page_cursor_: string | undefined,
22
  sort: "created" | "-created" | undefined,
23
  revision: string,
24
) {
25
  const url = new URL(`https://a.klaviyo.com/api/catalog-variants`);
26
  for (const [k, v] of [
27
    ["fields[catalog-variant]", fields_catalog_variant_],
28
    ["filter", filter],
29
    ["page[cursor]", page_cursor_],
30
    ["sort", sort],
31
  ]) {
32
    if (v !== undefined && v !== "" && k !== undefined) {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      revision: revision,
40
      "Accept": "application/vnd.api+json",
41
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
42
    },
43
    body: undefined,
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51