0

Update a Bill

by
Published Oct 17, 2025

Updates the details of an existing Bill.

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 Bill
7
 * Updates the details of an existing Bill.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  bill_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    purchaseorder_id?: number;
15
    vendor_id: number;
16
    bill_number: string;
17
    date: string;
18
    due_date: string;
19
    reference_number?: string;
20
    currency_id?: number;
21
    exchange_rate?: number;
22
    is_item_level_tax_calc?: false | true;
23
    notes?: string;
24
    terms?: string;
25
    is_inclusive_tax?: false | true;
26
    custom_fields?: { customfield_id?: number; value?: string }[];
27
    line_items: {
28
      purchaseorder_item_id?: number;
29
      receive_item_id?: number;
30
      line_item_id?: number;
31
      name?: string;
32
      account_id?: number;
33
      account_name?: string;
34
      description?: string;
35
      bcy_rate?: number;
36
      rate?: number;
37
      quantity?: number;
38
      tax_id?: number;
39
      tds_tax_id?: string;
40
      tax_name?: string;
41
      tax_type?: string;
42
      tax_percentage?: number;
43
      item_total?: number;
44
      item_order?: number;
45
      unit?: string;
46
      image_id?: number;
47
      image_name?: string;
48
      image_type?: string;
49
      reverse_charge_tax_id?: string;
50
      hsn_or_sac?: string;
51
      tax_exemption_code?: string;
52
      location_id?: string;
53
      tax_exemption_id?: string;
54
    }[];
55
    location_id?: string;
56
    gst_treatment?: string;
57
    tax_treatment?: string;
58
    gst_no?: string;
59
    source_of_supply?: string;
60
    destination_of_supply?: string;
61
    is_pre_gst?: false | true;
62
    is_reverse_charge_applied?: false | true;
63
  },
64
) {
65
  const url = new URL(`https://www.zohoapis.com/inventory/v1/bills/${bill_id}`);
66
  for (const [k, v] of [["organization_id", organization_id]]) {
67
    if (v !== undefined && v !== "" && k !== undefined) {
68
      url.searchParams.append(k, v);
69
    }
70
  }
71
  const response = await fetch(url, {
72
    method: "PUT",
73
    headers: {
74
      "Content-Type": "application/json",
75
      Authorization: "Zoho-oauthtoken " + auth.token,
76
    },
77
    body: JSON.stringify(body),
78
  });
79
  if (!response.ok) {
80
    const text = await response.text();
81
    throw new Error(`${response.status} ${text}`);
82
  }
83
  return await response.json();
84
}
85