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