//native
type Zoho = {
token: string;
};
/**
* Update a sales order 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[];
date?: string;
shipment_date?: string;
custom_fields?: { customfield_id?: number; value?: string }[];
place_of_supply?: string;
salesperson_id?: string;
merchant_id?: string;
gst_treatment?: string;
gst_no?: string;
is_inclusive_tax?: false | true;
location_id?: string;
line_items?: {
item_order?: number;
line_item_id?: string;
item_id?: string;
rate?: number;
name?: string;
description?: string;
quantity?: number;
discount?: string;
tax_id?: string;
tds_tax_id?: string;
tags?: { tag_id?: string; tag_option_id?: string }[];
unit?: string;
item_custom_fields?: { customfield_id?: number; value?: string }[];
tax_exemption_id?: string;
tax_exemption_code?: string;
tax_treatment_code?: string;
avatax_exempt_no?: string;
avatax_use_code?: string;
project_id?: string;
location_id?: string;
}[];
notes?: string;
terms?: string;
billing_address_id?: string;
shipping_address_id?: string;
crm_owner_id?: string;
crm_custom_reference_id?: string;
vat_treatment?: string;
tax_treatment?: string;
is_reverse_charge_applied?: false | true;
salesorder_number?: string;
reference_number?: string;
is_update_customer?: false | true;
discount?: string;
exchange_rate?: number;
salesperson_name?: string;
notes_default?: string;
terms_default?: string;
tax_id?: string;
tax_authority_id?: string;
tax_exemption_id?: string;
tax_authority_name?: string;
tax_exemption_code?: string;
avatax_exempt_no?: string;
avatax_use_code?: string;
shipping_charge?: number;
adjustment?: number;
delivery_method?: string;
is_discount_before_tax?: false | true;
discount_type?: string;
adjustment_description?: string;
pricebook_id?: string;
template_id?: string;
documents?: string[];
zcrm_potential_id?: string;
zcrm_potential_name?: string;
},
X_Upsert?: string,
) {
const url = new URL(`https://www.zohoapis.com/books/v3/salesorders`);
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