1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update opening balance |
7 | * Updates the existing opening balance information. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | body: { |
13 | date?: string; |
14 | accounts?: { |
15 | acount_split_id?: string; |
16 | account_id?: string; |
17 | account_name?: string; |
18 | debit_or_credit?: string; |
19 | exchange_rate?: number; |
20 | currency_id?: string; |
21 | currency_code?: string; |
22 | bcy_amount?: number; |
23 | amount?: number; |
24 | location_id?: string; |
25 | location_name?: string; |
26 | }[]; |
27 | opening_balance_id: string; |
28 | }, |
29 | ) { |
30 | const url = new URL( |
31 | `https://www.zohoapis.com/books/v3/settings/openingbalances`, |
32 | ); |
33 | for (const [k, v] of [["organization_id", organization_id]]) { |
34 | if (v !== undefined && v !== "" && k !== undefined) { |
35 | url.searchParams.append(k, v); |
36 | } |
37 | } |
38 | const response = await fetch(url, { |
39 | method: "PUT", |
40 | headers: { |
41 | "Content-Type": "application/json", |
42 | Authorization: "Zoho-oauthtoken " + auth.token, |
43 | }, |
44 | body: JSON.stringify(body), |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.json(); |
51 | } |
52 |
|