0

Create an Estimate

by
Published Oct 17, 2025

Create an estimate for your customer.

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 an Estimate
7
 * Create an estimate for your customer.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  send: 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(`https://www.zohoapis.com/books/v3/estimates`);
87
  for (const [k, v] of [
88
    ["organization_id", organization_id],
89
    ["send", send],
90
    ["ignore_auto_number_generation", ignore_auto_number_generation],
91
  ]) {
92
    if (v !== undefined && v !== "" && k !== undefined) {
93
      url.searchParams.append(k, v);
94
    }
95
  }
96
  const response = await fetch(url, {
97
    method: "POST",
98
    headers: {
99
      "Content-Type": "application/json",
100
      Authorization: "Zoho-oauthtoken " + auth.token,
101
    },
102
    body: JSON.stringify(body),
103
  });
104
  if (!response.ok) {
105
    const text = await response.text();
106
    throw new Error(`${response.status} ${text}`);
107
  }
108
  return await response.json();
109
}
110