//native
type Zoho = {
token: string;
};
/**
* Create a Sales Return
* Creation of Sales Return. Sales return can be created for all the shipped units of the items in a sales order.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
salesorder_id: string | undefined,
body: {
salesreturn_number?: string;
date?: string;
reason?: string;
custom_fields?: { customfield_id?: number; value?: string }[];
location_id?: string;
line_items: {
item_id?: number;
salesorder_item_id?: number;
quantity?: number;
non_receive_quantity?: number;
location_id?: string;
}[];
},
) {
const url = new URL(`https://www.zohoapis.com/inventory/v1/salesreturns`);
for (const [k, v] of [
["organization_id", organization_id],
["salesorder_id", salesorder_id],
]) {
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