//native
type Klaviyo = {
apiKey: string;
};
/**
* Update Coupon Code
* Updates a coupon code specified by the given identifier synchronously. We allow updating the 'status' and
'expires_at' of coupon codes.*Rate limits*:Burst: `350/s`Steady: `3500/m`
*/
export async function main(
auth: Klaviyo,
id: string,
revision: string,
body: {
data: {
type: "coupon-code";
id: string;
attributes: {
status?:
| "ASSIGNED_TO_PROFILE"
| "DELETING"
| "PROCESSING"
| "UNASSIGNED"
| "USED"
| "VERSION_NOT_ACTIVE";
expires_at?: string;
};
};
},
) {
const url = new URL(`https://a.klaviyo.com/api/coupon-codes/${id}`);
const response = await fetch(url, {
method: "PATCH",
headers: {
revision: revision,
"Accept": "application/vnd.api+json",
"Content-Type": "application/vnd.api+json",
Authorization: "Klaviyo-API-Key " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago