//native
type Zoho = {
token: string;
};
/**
* Update an recurring expense using a custom field's unique value
* A custom field will have unique values if it's configured to not accept duplicate values.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
X_Unique_Identifier_Key: string,
X_Unique_Identifier_Value: string,
body: {
account_id: string;
recurrence_name: string;
start_date: string;
end_date?: string;
recurrence_frequency: string;
repeat_every: string;
gst_no?: string;
source_of_supply?: string;
destination_of_supply?: string;
place_of_supply?: string;
reverse_charge_tax_id?: string;
location_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;
}[];
amount: number;
vat_treatment?: string;
tax_treatment?: string;
product_type?: string;
acquisition_vat_id?: string;
reverse_charge_vat_id?: string;
tax_id?: string;
is_inclusive_tax?: false | true;
is_billable?: false | true;
customer_id?: string;
project_id?: string;
currency_id?: string;
exchange_rate?: number;
custom_fields?: { customfield_id?: number; value?: string }[];
},
X_Upsert?: string,
) {
const url = new URL(`https://www.zohoapis.com/books/v3/recurringexpenses`);
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: {
"X-Unique-Identifier-Key": X_Unique_Identifier_Key,
"X-Unique-Identifier-Value": X_Unique_Identifier_Value,
...(X_Upsert ? { "X-Upsert": X_Upsert } : {}),
"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