0

Get Bulk Create Coupon Code Jobs

by
Published Apr 8, 2025

Get all coupon code bulk create jobs. Returns a maximum of 100 jobs per request.*Rate limits*:Burst: `75/s`Steady: `700/m` **Scopes:** `coupon-codes: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 Bulk Create Coupon Code Jobs
7
 * Get all coupon code bulk create jobs.
8

9
Returns a maximum of 100 jobs per request.*Rate limits*:Burst: `75/s`Steady: `700/m`
10

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