0

Buy one-time addon

by
Published Oct 17, 2025

Include a one-time addon in the subscription.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Buy one-time addon
7
 * Include a one-time addon in the subscription.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  subscription_id: string,
12
  X_com_zoho_subscriptions_organizationid: string,
13
  body: {
14
    addons: {
15
      addon_code: string;
16
      quantity?: number;
17
      tags?: { tag_id?: number; tag_option_id?: number }[];
18
      item_custom_fields?: { label?: string; value?: string }[];
19
      price?: number;
20
      tax_id: {};
21
      tax_exemption_id?: {};
22
      tax_exemption_code?: {};
23
      product_type?: string;
24
    }[];
25
    exchange_rate?: never;
26
    coupon_code?: {};
27
    add_to_unbilled_charges?: false | true;
28
  },
29
) {
30
  const url = new URL(
31
    `https://www.zohoapis.com/billing/v1/subscriptions/${subscription_id}/buyonetimeaddon`,
32
  );
33

34
  const response = await fetch(url, {
35
    method: "POST",
36
    headers: {
37
      "X-com-zoho-subscriptions-organizationid":
38
        X_com_zoho_subscriptions_organizationid,
39
      "Content-Type": "application/json",
40
      Authorization: "Zoho-oauthtoken " + auth.token,
41
    },
42
    body: JSON.stringify(body),
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50