//native
type Zoho = {
token: string;
};
/**
* Update a purchase 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: {
vendor_id: string;
currency_id?: string;
contact_persons?: string[];
purchaseorder_number?: string;
gst_treatment?: string;
tax_treatment?: {};
gst_no?: string;
source_of_supply?: string;
destination_of_supply?: string;
place_of_supply?: string;
pricebook_id?: string;
reference_number?: string;
discount?: string;
discount_account_id?: string;
is_discount_before_tax?: false | true;
billing_address_id?: number;
crm_owner_id?: string;
crm_custom_reference_id?: number;
template_id?: string;
date?: string;
delivery_date?: string;
due_date?: string;
exchange_rate?: number;
is_inclusive_tax?: false | true;
notes?: string;
notes_default?: string;
terms?: string;
terms_default?: string;
ship_via?: string;
delivery_org_address_id?: string;
delivery_customer_id?: string;
attention?: string;
vat_treatment?: string;
is_update_customer?: string;
salesorder_id?: number;
location_id?: string;
line_items: {
line_item_id?: string;
item_id?: string;
account_id?: string;
name?: string;
description?: string;
unit?: string;
location_id?: string;
hsn_or_sac?: string;
reverse_charge_tax_id?: string;
rate?: number;
quantity?: string;
item_order?: number;
tax_id?: string;
tds_tax_id?: string;
tax_treatment_code?: string;
tax_exemption_code?: string;
tax_exemption_id?: string;
acquisition_vat_id?: string;
reverse_charge_vat_id?: string;
item_custom_fields?: { index?: number; value?: string }[];
tags?: { tag_id?: number; tag_option_id?: number }[];
project_id?: string;
}[];
custom_fields?: { customfield_id?: number; value?: string }[];
documents?: { document_id?: number; file_name?: string }[];
},
X_Upsert?: string,
) {
const url = new URL(`https://www.zohoapis.com/books/v3/purchaseorders`);
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