0

Create List

by
Published Apr 8, 2025

Create a new list.*Rate limits*:Burst: `10/s`Steady: `150/m`Daily: `150/d` **Scopes:** `lists:write`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Create List
7
 * Create a new list.*Rate limits*:Burst: `10/s`Steady: `150/m`Daily: `150/d`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  revision: string,
13
  body: { data: { type: "list"; attributes: { name: string } } },
14
) {
15
  const url = new URL(`https://a.klaviyo.com/api/lists`);
16

17
  const response = await fetch(url, {
18
    method: "POST",
19
    headers: {
20
      revision: revision,
21
      "Accept": "application/vnd.api+json",
22
      "Content-Type": "application/vnd.api+json",
23
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
24
    },
25
    body: JSON.stringify(body),
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33