//native
type Klaviyo = {
apiKey: string;
};
/**
* Get Coupon For Coupon Code
* Get the coupon associated with a given coupon code ID.*Rate limits*:Burst: `75/s`Steady: `700/m`
*/
export async function main(
auth: Klaviyo,
id: string,
fields_coupon_: string | undefined,
revision: string,
) {
const url = new URL(`https://a.klaviyo.com/api/coupon-codes/${id}/coupon`);
for (const [k, v] of [["fields[coupon]", fields_coupon_]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
revision: revision,
"Accept": "application/vnd.api+json",
Authorization: "Klaviyo-API-Key " + auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago