//native
type Zoho = {
token: string;
};
/**
* Create an coupon
* Create a new coupon.
*/
export async function main(
auth: Zoho,
X_com_zoho_subscriptions_organizationid: string,
body: {
coupon_code: string;
name: string;
description?: string;
type: string;
duration: number;
discount_by: string;
discount_value?: number;
product_id: string;
max_redemption?: number;
expiry_at?: string;
apply_to_plans?: string;
plans: { plan_code: string }[];
apply_to_addons?: string;
addons: { addon_code: string }[];
},
) {
const url = new URL(`https://www.zohoapis.com/billing/v1/coupons`);
const response = await fetch(url, {
method: "POST",
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