//native
type Zoho = {
token: string;
};
/**
* Match a transaction
* Match an uncategorized transaction with an existing transaction in the account.
*/
export async function main(
auth: Zoho,
transaction_id: string,
organization_id: string | undefined,
account_id: string | undefined,
body: {
transactions_to_be_matched?: {
transaction_id?: string;
transaction_type?: string;
}[];
},
) {
const url = new URL(
`https://www.zohoapis.com/books/v3/banktransactions/uncategorized/${transaction_id}/match`,
);
for (const [k, v] of [
["organization_id", organization_id],
["account_id", account_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