0

Update a coupon

by
Published Oct 17, 2025

Update details of an existing coupon.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Update a coupon
7
 * Update details of an existing coupon.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  coupon_code: string,
12
  X_com_zoho_subscriptions_organizationid: string,
13
  body: {
14
    name: string;
15
    description?: string;
16
    max_redemption?: number;
17
    expiry_at?: string;
18
  },
19
) {
20
  const url = new URL(
21
    `https://www.zohoapis.com/billing/v1/coupons/${coupon_code}`,
22
  );
23

24
  const response = await fetch(url, {
25
    method: "PUT",
26
    headers: {
27
      "X-com-zoho-subscriptions-organizationid":
28
        X_com_zoho_subscriptions_organizationid,
29
      "Content-Type": "application/json",
30
      Authorization: "Zoho-oauthtoken " + auth.token,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40