0

Create a plan

by
Published Oct 17, 2025

Create a new plan.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Create a plan
7
 * Create a new plan.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  X_com_zoho_subscriptions_organizationid: string,
12
  body: {
13
    plan_code: string;
14
    name: string;
15
    recurring_price: number;
16
    unit?: string;
17
    interval: number;
18
    interval_unit?: string;
19
    billing_cycles?: number;
20
    trial_period?: number;
21
    setup_fee?: number;
22
    setup_fee_account_id?: string;
23
    tags?: { tag_id?: number; tag_option_id?: number }[];
24
    custom_fields?: { label?: string; value?: string }[];
25
    product_id: string;
26
    product_type?: string;
27
    hsn_or_sac?: string;
28
    sat_item_key_code?: string;
29
    unitkey_code?: string;
30
    item_tax_preferences?: {
31
      tax_specification?: string;
32
      tax_name?: string;
33
      tax_percentage?: number;
34
      tax_id?: string;
35
    }[];
36
    tax_id?: string;
37
    is_taxable?: string;
38
    tax_exemption_id?: string;
39
    tax_exemption_code?: string;
40
    description?: string;
41
    store_markup_description?: string;
42
    can_charge_setup_fee_immediately?: false | true;
43
  },
44
) {
45
  const url = new URL(`https://www.zohoapis.com/billing/v1/plans`);
46

47
  const response = await fetch(url, {
48
    method: "POST",
49
    headers: {
50
      "X-com-zoho-subscriptions-organizationid":
51
        X_com_zoho_subscriptions_organizationid,
52
      "Content-Type": "application/json",
53
      Authorization: "Zoho-oauthtoken " + auth.token,
54
    },
55
    body: JSON.stringify(body),
56
  });
57
  if (!response.ok) {
58
    const text = await response.text();
59
    throw new Error(`${response.status} ${text}`);
60
  }
61
  return await response.json();
62
}
63