1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a journal |
7 | * Create a journal. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | body: { |
13 | journal_date: string; |
14 | reference_number?: string; |
15 | notes?: string; |
16 | journal_type?: string; |
17 | vat_treatment?: string; |
18 | include_in_vat_return?: false | true; |
19 | product_type?: string; |
20 | is_bas_adjustment?: false | true; |
21 | currency_id?: string; |
22 | exchange_rate?: number; |
23 | location_id?: string; |
24 | line_items?: { |
25 | account_id?: string; |
26 | customer_id?: string; |
27 | line_id?: string; |
28 | description?: string; |
29 | tax_exemption_id?: string; |
30 | tax_authority_id?: string; |
31 | tax_exemption_type?: string; |
32 | tax_exemption_code?: string; |
33 | tax_authority_name?: string; |
34 | tax_id?: string; |
35 | amount: number; |
36 | debit_or_credit: string; |
37 | acquisition_vat_id?: string; |
38 | reverse_charge_vat_id?: string; |
39 | location_id?: string; |
40 | tags?: { tag_id?: number; tag_option_id?: number }[]; |
41 | project_id?: string; |
42 | }[]; |
43 | tax_exemption_code?: string; |
44 | tax_exemption_type?: string; |
45 | status?: string; |
46 | custom_fields?: { customfield_id?: string; value?: string }[]; |
47 | }, |
48 | ) { |
49 | const url = new URL(`https://www.zohoapis.com/books/v3/journals`); |
50 | for (const [k, v] of [["organization_id", organization_id]]) { |
51 | if (v !== undefined && v !== "" && k !== undefined) { |
52 | url.searchParams.append(k, v); |
53 | } |
54 | } |
55 | const response = await fetch(url, { |
56 | method: "POST", |
57 | headers: { |
58 | "Content-Type": "application/json", |
59 | Authorization: "Zoho-oauthtoken " + auth.token, |
60 | }, |
61 | body: JSON.stringify(body), |
62 | }); |
63 | if (!response.ok) { |
64 | const text = await response.text(); |
65 | throw new Error(`${response.status} ${text}`); |
66 | } |
67 | return await response.json(); |
68 | } |
69 |
|