//native
type Zoho = {
token: string;
};
/**
* update an Estimate using a custom field's unique value
* A custom field will have unique values if it's configured to not accept duplicate values.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
X_Unique_Identifier_Key: string,
X_Unique_Identifier_Value: string,
body: {
customer_id: string;
currency_id?: string;
contact_persons?: string[];
template_id?: string;
place_of_supply?: string;
gst_treatment?: string;
gst_no?: string;
estimate_number?: string;
reference_number?: string;
date?: string;
expiry_date?: string;
exchange_rate?: number;
discount?: number;
is_discount_before_tax?: false | true;
discount_type?: string;
is_inclusive_tax?: false | true;
custom_body?: string;
custom_subject?: string;
salesperson_name?: string;
custom_fields: { index?: number; value?: string }[];
line_items?: {
item_id?: string;
line_item_id?: string;
name?: string;
description?: string;
product_type?: string;
hsn_or_sac?: string;
sat_item_key_code?: string;
unitkey_code?: string;
item_order?: number;
bcy_rate?: number;
rate?: number;
quantity?: number;
unit?: string;
discount_amount?: number;
discount?: number;
tax_id?: string;
tds_tax_id?: string;
tax_name?: string;
tax_type?: string;
tax_percentage?: number;
tax_treatment_code?: string;
item_total?: number;
location_id?: string;
}[];
location_id?: string;
notes?: string;
terms?: string;
shipping_charge?: string;
adjustment?: number;
adjustment_description?: string;
tax_id?: string;
tax_exemption_id?: string;
tax_authority_id?: string;
avatax_use_code?: string;
avatax_exempt_no?: string;
vat_treatment?: string;
tax_treatment?: string;
is_reverse_charge_applied?: false | true;
item_id?: string;
line_item_id?: string;
name?: string;
description?: string;
rate?: number;
unit?: string;
quantity?: number;
project_id?: string;
accept_retainer?: false | true;
retainer_percentage?: number;
},
X_Upsert?: string,
) {
const url = new URL(`https://www.zohoapis.com/books/v3/estimates`);
for (const [k, v] of [["organization_id", organization_id]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
headers: {
"X-Unique-Identifier-Key": X_Unique_Identifier_Key,
"X-Unique-Identifier-Value": X_Unique_Identifier_Value,
...(X_Upsert ? { "X-Upsert": X_Upsert } : {}),
"Content-Type": "application/json",
Authorization: "Zoho-oauthtoken " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago