//native
type Zoho = {
token: string;
};
/**
* Create a Purchase Order
* Creates a new Purchase Order in Zoho Inventory. Description about extra parameter ignore_auto_number_generation - Ignore auto purchase order number generation for this Purchase order. This mandates the Purchase Order number to be entered. Allowed Values true and false.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
ignore_auto_number_generation: string | undefined,
body: {
purchaseorder_number: string;
date?: string;
delivery_date?: string;
reference_number?: string;
ship_via?: string;
vendor_id: number;
salesorder_id?: number;
is_drop_shipment?: false | true;
is_inclusive_tax?: false | true;
is_backorder?: false | true;
template_id?: number;
contact_persons?: { contact_person_id?: number }[];
attention?: string;
delivery_org_address_id?: number;
delivery_customer_id?: number;
notes?: string;
terms?: string;
exchange_rate?: number;
custom_fields?: { customfield_id?: number; value?: string }[];
line_items: {
item_id?: number;
account_id?: number;
name?: string;
description?: string;
item_order?: number;
bcy_rate?: number;
purchase_rate?: number;
quantity?: number;
quantity_received?: number;
unit?: string;
item_total?: number;
tax_id?: number;
tds_tax_id?: string;
tax_name?: string;
tax_type?: string;
tax_percentage?: number;
image_id?: number;
image_name?: string;
image_type?: string;
reverse_charge_tax_id?: string;
hsn_or_sac?: string;
tax_exemption_code?: string;
location_id?: string;
tax_exemption_id?: string;
salesorder_item_id?: number;
}[];
location_id?: string;
documents?: {
can_send_in_mail?: false | true;
file_name?: string;
file_type?: string;
file_size_formatted?: string;
attachment_order?: number;
document_id?: number;
file_size?: number;
}[];
gst_treatment?: string;
tax_treatment?: {};
gst_no?: string;
source_of_supply?: string;
destination_of_supply?: string;
},
) {
const url = new URL(`https://www.zohoapis.com/inventory/v1/purchaseorders`);
for (const [k, v] of [
["organization_id", organization_id],
["ignore_auto_number_generation", ignore_auto_number_generation],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"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