//native
type Zoho = {
token: string;
};
/**
* Create a transaction for an account
* Create a bank transaction based on the allowed transaction types.
*/
export async function main(
auth: Zoho,
organization_id: string | undefined,
body: {
from_account_id?: string;
to_account_id?: string;
transaction_type: string;
amount?: number;
payment_mode?: string;
exchange_rate?: number;
date?: string;
customer_id?: string;
reference_number?: string;
description?: string;
currency_id?: string;
tax_id?: string;
is_inclusive_tax?: false | true;
tags?: { tag_id?: number; tag_option_id?: number }[];
from_account_tags?: { tag_id?: number; tag_option_id?: number }[];
to_account_tags?: { tag_id?: number; tag_option_id?: number }[];
documents?: { file_name?: {}; document_id?: {} }[];
bank_charges?: number;
user_id?: number;
tax_authority_id?: string;
tax_exemption_id?: string;
custom_fields?: {
custom_field_id?: number;
index?: number;
label?: string;
value?: string;
}[];
},
) {
const url = new URL(`https://www.zohoapis.com/books/v3/banktransactions`);
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: "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