//native
type Zoho = {
token: string;
};
/**
* Update a Sales Return
* Updation of Sales Return.
*/
export async function main(
auth: Zoho,
salesreturn_id: string,
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: {
line_item_id?: number;
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/${salesreturn_id}`,
);
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: "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