0

Update a subscription

by
Published Oct 17, 2025

Update details of an existing 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
 * Update a subscription
7
 * Update details of an existing subscription.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  subscription_id: string,
12
  X_com_zoho_subscriptions_organizationid: string,
13
  body: {
14
    card_id: {};
15
    exchange_rate?: never;
16
    plan: {
17
      plan_code: string;
18
      plan_description?: string;
19
      price?: number;
20
      setup_fee?: never;
21
      quantity?: number;
22
      tags?: { tag_id?: number; tag_option_id?: number }[];
23
      item_custom_fields?: { label?: string; value?: string }[];
24
      tax_id: {};
25
      tax_exemption_id?: string;
26
      tax_exemption_code?: string;
27
      tds_tax_id?: string;
28
      sat_item_key_code?: string;
29
      unitkey_code?: string;
30
      setup_fee_tax_exemption_id?: string;
31
      setup_fee_tax_exemption_code?: string;
32
      exclude_trial?: false | true;
33
      exclude_setup_fee?: false | true;
34
      billing_cycles?: number;
35
      trial_days?: never;
36
    };
37
    addons?: {
38
      addon_code: string;
39
      addon_description?: string;
40
      price?: number;
41
      quantity?: {};
42
      tags?: { tag_id?: number; tag_option_id?: number }[];
43
      item_custom_fields?: { label?: string; value?: string }[];
44
      tax_id: {};
45
      tax_exemption_id?: string;
46
      tax_exemption_code?: string;
47
      tds_tax_id?: string;
48
      sat_item_key_code?: string;
49
      unitkey_code?: string;
50
    }[];
51
    auto_collect?: false | true;
52
    coupon_code?: string;
53
    reference_id?: string;
54
    salesperson_id?: string;
55
    salesperson_name?: string;
56
    end_of_term?: false | true;
57
    contactpersons?: { contactperson_id: string }[];
58
    payment_terms?: number;
59
    payment_terms_label?: string;
60
    payment_gateways?: { payment_gateway?: {} }[];
61
    custom_fields?: {
62
      index?: number;
63
      label?: string;
64
      value?: string;
65
      data_type?: string;
66
    }[];
67
    template_id?: string;
68
    can_charge_setup_fee_immediately?: false | true;
69
    cfdi_usage?: string;
70
    allow_partial_payments?: false | true;
71
    customer_id: string;
72
    account_id: string;
73
  },
74
) {
75
  const url = new URL(
76
    `https://www.zohoapis.com/billing/v1/subscriptions/${subscription_id}`,
77
  );
78

79
  const response = await fetch(url, {
80
    method: "PUT",
81
    headers: {
82
      "X-com-zoho-subscriptions-organizationid":
83
        X_com_zoho_subscriptions_organizationid,
84
      "Content-Type": "application/json",
85
      Authorization: "Zoho-oauthtoken " + auth.token,
86
    },
87
    body: JSON.stringify(body),
88
  });
89
  if (!response.ok) {
90
    const text = await response.text();
91
    throw new Error(`${response.status} ${text}`);
92
  }
93
  return await response.json();
94
}
95