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