//native
type Zoho = {
token: string;
};
/**
* Update a Purchase Receive
* Update a existing Purchase Receive from Zoho Inventory.
*/
export async function main(
auth: Zoho,
purchasereceive_id: string,
organization_id: string | undefined,
body: {
receive_number: string;
date?: string;
notes?: string;
custom_fields?: { customfield_id?: number; value?: string }[];
line_items: {
line_item_id?: number;
item_id?: number;
name?: string;
description?: string;
item_order?: number;
quantity?: number;
unit?: string;
}[];
},
) {
const url = new URL(
`https://www.zohoapis.com/inventory/v1/purchasereceives/${purchasereceive_id}`,
);
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: {
"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