1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a transaction for an account |
7 | * Create a bank transaction based on the allowed transaction types. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | body: { |
13 | from_account_id?: string; |
14 | to_account_id?: string; |
15 | transaction_type: string; |
16 | amount?: number; |
17 | payment_mode?: string; |
18 | exchange_rate?: number; |
19 | date?: string; |
20 | customer_id?: string; |
21 | reference_number?: string; |
22 | description?: string; |
23 | currency_id?: string; |
24 | tax_id?: string; |
25 | is_inclusive_tax?: false | true; |
26 | tags?: { tag_id?: number; tag_option_id?: number }[]; |
27 | from_account_tags?: { tag_id?: number; tag_option_id?: number }[]; |
28 | to_account_tags?: { tag_id?: number; tag_option_id?: number }[]; |
29 | documents?: { file_name?: {}; document_id?: {} }[]; |
30 | bank_charges?: number; |
31 | user_id?: number; |
32 | tax_authority_id?: string; |
33 | tax_exemption_id?: string; |
34 | custom_fields?: { |
35 | custom_field_id?: number; |
36 | index?: number; |
37 | label?: string; |
38 | value?: string; |
39 | }[]; |
40 | }, |
41 | ) { |
42 | const url = new URL(`https://www.zohoapis.com/books/v3/banktransactions`); |
43 | for (const [k, v] of [["organization_id", organization_id]]) { |
44 | if (v !== undefined && v !== "" && k !== undefined) { |
45 | url.searchParams.append(k, v); |
46 | } |
47 | } |
48 | const response = await fetch(url, { |
49 | method: "POST", |
50 | headers: { |
51 | "Content-Type": "application/json", |
52 | Authorization: "Zoho-oauthtoken " + auth.token, |
53 | }, |
54 | body: JSON.stringify(body), |
55 | }); |
56 | if (!response.ok) { |
57 | const text = await response.text(); |
58 | throw new Error(`${response.status} ${text}`); |
59 | } |
60 | return await response.json(); |
61 | } |
62 |
|