0

Update an invoice

by
Published Oct 17, 2025

Update an existing invoice. To delete a line item just remove it from the line_items list.

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 an invoice
7
 * Update an existing invoice. To delete a line item just remove it from the line_items list.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  invoice_id: string,
12
  organization_id: string | undefined,
13
  ignore_auto_number_generation: string | undefined,
14
  body: {
15
    customer_id: string;
16
    contact_persons?: {
17
      contact_person_id?: string;
18
      salutation?: string;
19
      first_name?: string;
20
      last_name?: string;
21
      email?: {};
22
      phone?: string;
23
      mobile?: string;
24
      is_primary_contact?: {};
25
    }[];
26
    invoice_number?: string;
27
    reference_number?: string;
28
    template_id?: string;
29
    date?: string;
30
    payment_terms?: number;
31
    payment_terms_label?: string;
32
    due_date?: string;
33
    discount?: number;
34
    is_discount_before_tax?: false | true;
35
    discount_type?: string;
36
    is_inclusive_tax?: false | true;
37
    exchange_rate?: number;
38
    recurring_invoice_id?: string;
39
    invoiced_estimate_id?: string;
40
    salesperson_name?: string;
41
    custom_fields?: {
42
      index?: number;
43
      show_on_pdf?: false | true;
44
      value?: string;
45
      label?: string;
46
    }[];
47
    project_id?: string;
48
    line_items: {
49
      line_item_id?: string;
50
      item_id?: string;
51
      project_id?: string;
52
      time_entry_ids?: string;
53
      expense_id?: string;
54
      expense_receipt_name?: string;
55
      name?: string;
56
      description?: string;
57
      item_order?: number;
58
      bcy_rate?: number;
59
      rate?: number;
60
      quantity?: number;
61
      unit?: string;
62
      discount_amount?: number;
63
      discount?: number;
64
      tax_id?: string;
65
      tds_tax_id?: string;
66
      tax_name?: string;
67
      tax_type?: string;
68
      tax_percentage?: number;
69
      item_total?: number;
70
      location_id?: string;
71
      hsn_or_sac?: string;
72
      sat_item_key_code?: string;
73
      unitkey_code?: string;
74
    }[];
75
    location_id?: string;
76
    payment_options?: {
77
      payment_gateways?: {
78
        configured?: false | true;
79
        additional_field1?: string;
80
        gateway_name?: string;
81
      }[];
82
    };
83
    allow_partial_payments?: false | true;
84
    custom_body?: string;
85
    custom_subject?: string;
86
    notes?: string;
87
    terms?: string;
88
    shipping_charge?: string;
89
    adjustment?: number;
90
    adjustment_description?: string;
91
    reason?: string;
92
    tax_authority_id?: string;
93
    tax_exemption_id?: string;
94
    avatax_use_code?: string;
95
    avatax_exempt_no?: string;
96
    vat_treatment?: string;
97
    tax_treatment?: string;
98
    billing_address_id?: number;
99
    shipping_address_id?: number;
100
    gst_no?: string;
101
    gst_treatment?: string;
102
    place_of_supply?: string;
103
    cfdi_usage?: string;
104
    cfdi_reference_type?: string;
105
    reference_invoice_id?: string;
106
  },
107
) {
108
  const url = new URL(
109
    `https://www.zohoapis.com/inventory/v1/invoices/${invoice_id}`,
110
  );
111
  for (const [k, v] of [
112
    ["organization_id", organization_id],
113
    ["ignore_auto_number_generation", ignore_auto_number_generation],
114
  ]) {
115
    if (v !== undefined && v !== "" && k !== undefined) {
116
      url.searchParams.append(k, v);
117
    }
118
  }
119
  const response = await fetch(url, {
120
    method: "PUT",
121
    headers: {
122
      "Content-Type": "application/json",
123
      Authorization: "Zoho-oauthtoken " + auth.token,
124
    },
125
    body: JSON.stringify(body),
126
  });
127
  if (!response.ok) {
128
    const text = await response.text();
129
    throw new Error(`${response.status} ${text}`);
130
  }
131
  return await response.json();
132
}
133