//native
type Zoho = {
token: string;
};
/**
* update a retainerinvoice
* Update an existing invoice.
*/
export async function main(
auth: Zoho,
retainerinvoice_id: string,
organization_id: string | undefined,
body: {
customer_id: string;
reference_number?: string;
date?: string;
contact_persons?: string[];
custom_fields?: {
index?: number;
show_on_pdf?: false | true;
value?: string;
label?: string;
}[];
notes?: string;
terms?: string;
location_id?: string;
line_items: { description?: string; item_order?: number; rate?: number }[];
payment_options?: {
payment_gateways?: {
configured?: false | true;
additional_field1?: string;
gateway_name?: string;
}[];
};
template_id?: string;
place_of_supply?: string;
project_id?: string;
},
) {
const url = new URL(
`https://www.zohoapis.com/inventory/v1/retainerinvoices/${retainerinvoice_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