//native
type Zoho = {
token: string;
};
/**
* Categorize as expense
* Categorize an Uncategorized transaction as expense.
*/
export async function main(
auth: Zoho,
transaction_id: string,
organization_id: string | undefined,
doc: string | undefined,
totalFiles: string | undefined,
document_ids: string | undefined,
body: {
account_id?: string;
paid_through_account_id?: string;
date?: string;
tax_id?: string;
amount?: number;
project_id?: string;
tax_exemption_code?: string;
tax_exemption_id?: string;
is_inclusive_tax?: false | true;
is_billable?: false | true;
reference_number?: string;
description?: string;
customer_id?: string;
zp_project_id?: number;
zp_project_name?: string;
zp_client_id?: number;
vendor_id?: string;
vehicle_id?: string;
mileage_unit?: string;
mileage_rate?: number;
can_reclaim_vat_on_mileage?: false | true;
fuel_type?: string;
engine_capacity_range?: string;
employee_id?: number;
mileage_type?: string;
expense_type?: string;
distance?: number;
start_reading?: string;
end_reading?: string;
currency_id?: string;
custom_fields?: { index?: number; value?: string }[];
tags?: { tag_id?: number; tag_option_id?: number }[];
documents?: { file_name?: {}; document_id?: {} }[];
exchange_rate?: number;
recurring_expense_id?: number;
vat_treatment?: string;
tax_treatment?: string;
acquisition_vat_id?: string;
reverse_charge_vat_id?: string;
is_update_customer?: false | true;
product_type?: string;
taxes?: { tax_name?: string; tax_amount?: number; tax_id?: string }[];
reason?: string;
line_items?: {
line_item_id?: number;
account_id?: string;
description?: string;
amount?: number;
tax_id?: string;
item_order?: number;
product_type?: string;
acquisition_vat_id?: string;
reverse_charge_vat_id?: string;
tax_exemption_code?: string;
tax_exemption_id?: string;
tags?: { tag_id?: number; tag_option_id?: number }[];
}[];
zcrm_potential_id?: number;
},
) {
const url = new URL(
`https://www.zohoapis.com/books/v3/banktransactions/uncategorized/${transaction_id}/categorize/expenses`,
);
for (const [k, v] of [
["organization_id", organization_id],
["doc", doc],
["totalFiles", totalFiles],
["document_ids", document_ids],
]) {
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