0

Update a recurring bill using a custom field's unique value

by
Published Oct 17, 2025

A custom field will have unique values if it's configured to not accept duplicate values.

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 recurring bill using a custom field's unique value
7
 * A custom field will have unique values if it's configured to not accept duplicate values.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  X_Unique_Identifier_Key: string,
13
  X_Unique_Identifier_Value: string,
14
  X_Upsert?: string,
15
  body: {
16
    recurring_bill_id?: string;
17
    vendor_id: string;
18
    currency_id?: string;
19
    status?: string;
20
    recurrence_name: string;
21
    start_date: string;
22
    end_date?: string;
23
    source_of_supply?: string;
24
    place_of_supply?: string;
25
    destination_of_supply?: string;
26
    gst_treatment?: string;
27
    gst_no?: string;
28
    tax_treatment?: string;
29
    vat_treatment?: string;
30
    vat_reg_no?: string;
31
    is_abn_quoted?: string;
32
    abn?: string;
33
    is_reverse_charge_applied?: false | true;
34
    pricebook_id?: string;
35
    pricebook_name?: string;
36
    is_inclusive_tax?: false | true;
37
    location_id?: string;
38
    line_items?: {
39
      line_item_id?: string;
40
      item_id?: string;
41
      name?: string;
42
      account_id?: string;
43
      description?: string;
44
      rate?: number;
45
      hsn_or_sac?: string;
46
      reverse_charge_tax_id?: string;
47
      location_id?: string;
48
      quantity?: number;
49
      tax_id?: string;
50
      tds_tax_id?: string;
51
      tax_treatment_code?: string;
52
      tax_exemption_id?: string;
53
      tax_exemption_code?: string;
54
      item_order?: number;
55
      product_type?: string;
56
      acquisition_vat_id?: string;
57
      reverse_charge_vat_id?: string;
58
      unit?: string;
59
      tags?: { tag_id?: number; tag_option_id?: number }[];
60
      is_billable?: false | true;
61
      project_id?: string;
62
      customer_id?: string;
63
      item_custom_fields?: {
64
        custom_field_id?: number;
65
        index?: number;
66
        value?: string;
67
        label?: string;
68
      }[];
69
      serial_numbers?: string[];
70
    }[];
71
    is_tds_applied?: false | true;
72
    notes?: string;
73
    terms?: string;
74
    payment_terms?: number;
75
    payment_terms_label?: string;
76
    custom_fields?: { index?: number; value?: string }[];
77
    discount?: string;
78
    discount_account_id?: string;
79
    is_discount_before_tax?: false | true;
80
    repeat_every: string;
81
    recurrence_frequency: string;
82
  },
83
) {
84
  const url = new URL(`https://www.zohoapis.com/books/v3/recurringbills`);
85
  for (const [k, v] of [["organization_id", organization_id]]) {
86
    if (v !== undefined && v !== "") {
87
      url.searchParams.append(k, v);
88
    }
89
  }
90
  const response = await fetch(url, {
91
    method: "PUT",
92
    headers: {
93
      "X-Unique-Identifier-Key": X_Unique_Identifier_Key,
94
      "X-Unique-Identifier-Value": X_Unique_Identifier_Value,
95
      ...(X_Upsert ? { "X-Upsert": X_Upsert } : {}),
96
      "Content-Type": "application/json",
97
      Authorization: "Zoho-oauthtoken " + auth.token,
98
    },
99
    body: JSON.stringify(body),
100
  });
101
  if (!response.ok) {
102
    const text = await response.text();
103
    throw new Error(`${response.status} ${text}`);
104
  }
105
  return await response.json();
106
}
107