1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Match a transaction |
7 | * Match an uncategorized transaction with an existing transaction in the account. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | transaction_id: string, |
12 | organization_id: string | undefined, |
13 | account_id: string | undefined, |
14 | body: { |
15 | transactions_to_be_matched?: { |
16 | transaction_id?: string; |
17 | transaction_type?: string; |
18 | }[]; |
19 | }, |
20 | ) { |
21 | const url = new URL( |
22 | `https://www.zohoapis.com/books/v3/banktransactions/uncategorized/${transaction_id}/match`, |
23 | ); |
24 | for (const [k, v] of [ |
25 | ["organization_id", organization_id], |
26 | ["account_id", account_id], |
27 | ]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "POST", |
34 | headers: { |
35 | "Content-Type": "application/json", |
36 | Authorization: "Zoho-oauthtoken " + auth.token, |
37 | }, |
38 | body: JSON.stringify(body), |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|