0

Get Coupon ID for Coupon Code

by
Published Apr 8, 2025

Gets the coupon relationship associated with the given coupon code id*Rate limits*:Burst: `75/s`Steady: `700/m` **Scopes:** `coupons: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 Coupon ID for Coupon Code
7
 * Gets the coupon relationship associated with the given coupon code id*Rate limits*:Burst: `75/s`Steady: `700/m`
8

9
 */
10
export async function main(auth: Klaviyo, id: string, revision: string) {
11
  const url = new URL(
12
    `https://a.klaviyo.com/api/coupon-codes/${id}/relationships/coupon`,
13
  );
14

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