1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a transaction |
7 | * Make changes in the applicable fields of a transaction and update it. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | bank_transaction_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | from_account_id?: string; |
15 | to_account_id?: string; |
16 | transaction_type: string; |
17 | amount?: number; |
18 | payment_mode?: string; |
19 | exchange_rate?: number; |
20 | date?: string; |
21 | customer_id?: string; |
22 | reference_number?: string; |
23 | description?: string; |
24 | currency_id?: string; |
25 | tax_id?: string; |
26 | is_inclusive_tax?: false | true; |
27 | tags?: { tag_id?: number; tag_option_id?: number }[]; |
28 | from_account_tags?: { tag_id?: number; tag_option_id?: number }[]; |
29 | to_account_tags?: { tag_id?: number; tag_option_id?: number }[]; |
30 | documents?: { file_name?: {}; document_id?: {} }[]; |
31 | bank_charges?: number; |
32 | user_id?: number; |
33 | tax_authority_id?: string; |
34 | tax_exemption_id?: string; |
35 | custom_fields?: { |
36 | custom_field_id?: number; |
37 | index?: number; |
38 | label?: string; |
39 | value?: string; |
40 | }[]; |
41 | line_items?: { |
42 | line_id?: number; |
43 | account_id?: string; |
44 | account_name?: string; |
45 | description?: string; |
46 | tax_amount?: number; |
47 | tax_id?: string; |
48 | tax_name?: string; |
49 | tax_type?: string; |
50 | tax_percentage?: number; |
51 | item_total?: number; |
52 | item_total_inclusive_of_tax?: number; |
53 | item_order?: number; |
54 | tags?: { tag_id?: number; tag_option_id?: number }[]; |
55 | }[]; |
56 | }, |
57 | ) { |
58 | const url = new URL( |
59 | `https://www.zohoapis.com/books/v3/banktransactions/${bank_transaction_id}`, |
60 | ); |
61 | for (const [k, v] of [["organization_id", organization_id]]) { |
62 | if (v !== undefined && v !== "" && k !== undefined) { |
63 | url.searchParams.append(k, v); |
64 | } |
65 | } |
66 | const response = await fetch(url, { |
67 | method: "PUT", |
68 | headers: { |
69 | "Content-Type": "application/json", |
70 | Authorization: "Zoho-oauthtoken " + auth.token, |
71 | }, |
72 | body: JSON.stringify(body), |
73 | }); |
74 | if (!response.ok) { |
75 | const text = await response.text(); |
76 | throw new Error(`${response.status} ${text}`); |
77 | } |
78 | return await response.json(); |
79 | } |
80 |
|