//native
type Zoho = {
token: string;
};
/**
* Update a coupon
* Update details of an existing coupon.
*/
export async function main(
auth: Zoho,
coupon_code: string,
X_com_zoho_subscriptions_organizationid: string,
body: {
name: string;
description?: string;
max_redemption?: number;
expiry_at?: string;
},
) {
const url = new URL(
`https://www.zohoapis.com/billing/v1/coupons/${coupon_code}`,
);
const response = await fetch(url, {
method: "PUT",
headers: {
"X-com-zoho-subscriptions-organizationid":
X_com_zoho_subscriptions_organizationid,
"Content-Type": "application/json",
Authorization: "Zoho-oauthtoken " + auth.token,
},
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 235 days ago