0

Update Coupon

by
Published Apr 8, 2025

*Rate limits*:Burst: `3/s`Steady: `60/m` **Scopes:** `coupons: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
 * Update Coupon
7
 * *Rate limits*:Burst: `3/s`Steady: `60/m`
8

9
 */
10
export async function main(
11
  auth: Klaviyo,
12
  id: string,
13
  revision: string,
14
  body: {
15
    data: { type: "coupon"; id: string; attributes: { description?: string } };
16
  },
17
) {
18
  const url = new URL(`https://a.klaviyo.com/api/coupons/${id}`);
19

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