0

Update an Estimate

by
Published Oct 17, 2025

Update an existing estimate. 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 Estimate
7
 * Update an existing estimate. To delete a line item just remove it from the line_items list.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  estimate_id: string,
12
  organization_id: string | undefined,
13
  ignore_auto_number_generation: string | undefined,
14
  body: {
15
    customer_id: string;
16
    currency_id?: string;
17
    contact_persons?: string[];
18
    template_id?: string;
19
    place_of_supply?: string;
20
    gst_treatment?: string;
21
    gst_no?: string;
22
    estimate_number?: string;
23
    reference_number?: string;
24
    date?: string;
25
    expiry_date?: string;
26
    exchange_rate?: number;
27
    discount?: number;
28
    is_discount_before_tax?: false | true;
29
    discount_type?: string;
30
    is_inclusive_tax?: false | true;
31
    custom_body?: string;
32
    custom_subject?: string;
33
    salesperson_name?: string;
34
    custom_fields: { index?: number; value?: string }[];
35
    line_items?: {
36
      item_id?: string;
37
      line_item_id?: string;
38
      name?: string;
39
      description?: string;
40
      product_type?: string;
41
      hsn_or_sac?: string;
42
      sat_item_key_code?: string;
43
      unitkey_code?: string;
44
      item_order?: number;
45
      bcy_rate?: number;
46
      rate?: number;
47
      quantity?: number;
48
      unit?: string;
49
      discount_amount?: number;
50
      discount?: number;
51
      tax_id?: string;
52
      tds_tax_id?: string;
53
      tax_name?: string;
54
      tax_type?: string;
55
      tax_percentage?: number;
56
      tax_treatment_code?: string;
57
      item_total?: number;
58
      location_id?: string;
59
    }[];
60
    location_id?: string;
61
    notes?: string;
62
    terms?: string;
63
    shipping_charge?: string;
64
    adjustment?: number;
65
    adjustment_description?: string;
66
    tax_id?: string;
67
    tax_exemption_id?: string;
68
    tax_authority_id?: string;
69
    avatax_use_code?: string;
70
    avatax_exempt_no?: string;
71
    vat_treatment?: string;
72
    tax_treatment?: string;
73
    is_reverse_charge_applied?: false | true;
74
    item_id?: string;
75
    line_item_id?: string;
76
    name?: string;
77
    description?: string;
78
    rate?: number;
79
    unit?: string;
80
    quantity?: number;
81
    project_id?: string;
82
    accept_retainer?: false | true;
83
    retainer_percentage?: number;
84
  },
85
) {
86
  const url = new URL(
87
    `https://www.zohoapis.com/books/v3/estimates/${estimate_id}`,
88
  );
89
  for (const [k, v] of [
90
    ["organization_id", organization_id],
91
    ["ignore_auto_number_generation", ignore_auto_number_generation],
92
  ]) {
93
    if (v !== undefined && v !== "" && k !== undefined) {
94
      url.searchParams.append(k, v);
95
    }
96
  }
97
  const response = await fetch(url, {
98
    method: "PUT",
99
    headers: {
100
      "Content-Type": "application/json",
101
      Authorization: "Zoho-oauthtoken " + auth.token,
102
    },
103
    body: JSON.stringify(body),
104
  });
105
  if (!response.ok) {
106
    const text = await response.text();
107
    throw new Error(`${response.status} ${text}`);
108
  }
109
  return await response.json();
110
}
111