0

Buy one-time addon for a subscription

by
Published Oct 17, 2025

Create hosted page for buying a one-time addon for a 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 for a subscription
7
 * Create hosted page for buying a one-time addon for a subscription.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  X_com_zoho_subscriptions_organizationid: string,
12
  body: {
13
    subscription_id: string;
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?: string;
22
      tax_exemption_code?: string;
23
      product_type?: string;
24
    }[];
25
    redirect_url?: string;
26
    coupon_code?: {};
27
    cfdi_usage?: string;
28
    exchange_rate?: never;
29
    payment_gateways?: { payment_gateway?: string }[];
30
  },
31
) {
32
  const url = new URL(
33
    `https://www.zohoapis.com/billing/v1/hostedpages/buyonetimeaddon`,
34
  );
35

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