//native
type Zoho = {
token: string;
};
/**
* Update an Expense
* Update an existing Expense.
*/
export async function main(
auth: Zoho,
expense_id: string,
organization_id: string | undefined,
receipt: string | undefined,
delete_receipt: string | undefined,
body: {
account_id: string;
date: string;
amount: number;
tax_id?: string;
source_of_supply?: string;
destination_of_supply?: string;
place_of_supply?: string;
hsn_or_sac?: string;
gst_no?: string;
reverse_charge_tax_id?: string;
line_items?: {
line_item_id?: string;
account_id?: string;
description?: string;
amount?: number;
tax_id?: string;
item_order?: string;
product_type?: string;
acquisition_vat_id?: string;
reverse_charge_vat_id?: string;
reverse_charge_tax_id?: string;
tax_exemption_code?: string;
tax_exemption_id?: string;
location_id?: string;
}[];
location_id?: string;
taxes?: { tax_id?: string; tax_amount?: number }[];
is_inclusive_tax?: false | true;
is_billable?: false | true;
reference_number?: string;
description?: string;
customer_id?: string;
currency_id?: string;
exchange_rate?: number;
project_id?: string;
mileage_type?: string;
vat_treatment?: string;
tax_treatment?: string;
product_type?: string;
acquisition_vat_id?: string;
reverse_charge_vat_id?: string;
start_reading?: number;
end_reading?: number;
distance?: string;
mileage_unit?: string;
mileage_rate?: number;
employee_id?: string;
vehicle_type?: string;
can_reclaim_vat_on_mileage?: string;
fuel_type?: string;
engine_capacity_range?: string;
paid_through_account_id: string;
vendor_id?: string;
custom_fields?: string[];
},
) {
const url = new URL(
`https://www.zohoapis.com/books/v3/expenses/${expense_id}`,
);
for (const [k, v] of [
["organization_id", organization_id],
["receipt", receipt],
["delete_receipt", delete_receipt],
]) {
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