//native
type Zoho = {
token: string;
};
/**
* Categorize as customer payment
* Categorize an uncategorized transaction as Customer Payment.
*/
export async function main(
auth: Zoho,
transaction_id: string,
organization_id: string | undefined,
body: {
customer_id?: string;
retainerinvoice_id?: number;
invoices?: {
invoice_payment_id?: number;
invoice_id?: number;
amount_applied?: number;
tax_amount_withheld?: number;
discount_amount?: number;
}[];
payment_mode?: string;
description?: string;
reference_number?: string;
exchange_rate?: number;
amount?: number;
bank_charges?: number;
account_id?: string;
custom_fields?: { index?: number; value?: string }[];
documents?: { file_name?: {}; document_id?: {} }[];
date?: string;
template_id?: number;
contact_persons?: string[];
},
) {
const url = new URL(
`https://www.zohoapis.com/books/v3/banktransactions/uncategorized/${transaction_id}/categorize/customerpayments`,
);
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