1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a recurring invoice 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 | recurrence_name: string; |
16 | reference_number?: string; |
17 | customer_id: string; |
18 | currency_id?: string; |
19 | contact_persons?: string[]; |
20 | start_date?: string; |
21 | end_date?: string; |
22 | recurrence_frequency: "weeks"; |
23 | repeat_every?: number; |
24 | place_of_supply?: string; |
25 | vat_treatment?: string; |
26 | gst_treatment?: string; |
27 | tax_treatment?: string; |
28 | is_reverse_charge_applied?: false | true; |
29 | cfdi_usage?: string; |
30 | allow_partial_payments?: false | true; |
31 | gst_no?: string; |
32 | location_id?: string; |
33 | line_items?: { |
34 | item_id?: string; |
35 | name?: string; |
36 | description?: string; |
37 | rate?: number; |
38 | quantity?: number; |
39 | discount?: string; |
40 | tags?: { tag_id?: string; tag_option_id?: string }[]; |
41 | tax_id?: {}; |
42 | tds_tax_id?: string; |
43 | tax_exemption_id?: string; |
44 | tax_treatment_code?: string; |
45 | avatax_tax_code?: string; |
46 | avatax_use_code?: string; |
47 | item_total?: number; |
48 | product_type?: string; |
49 | hsn_or_sac?: string; |
50 | sat_item_key_code?: string; |
51 | unitkey_code?: string; |
52 | location_id?: string; |
53 | project_id?: string; |
54 | header_name?: string; |
55 | header_id?: string; |
56 | }[]; |
57 | email?: string; |
58 | custom_fields?: { value?: string; label?: string; data_type?: string }[]; |
59 | tax_id?: {}; |
60 | tax_authority_id?: string; |
61 | payment_options?: { |
62 | payment_gateways?: { |
63 | configured?: false | true; |
64 | additional_field1?: string; |
65 | gateway_name?: string; |
66 | }[]; |
67 | }; |
68 | tax_exemption_id?: string; |
69 | avatax_use_code?: string; |
70 | avatax_exempt_no?: string; |
71 | }, |
72 | X_Upsert?: string, |
73 | ) { |
74 | const url = new URL(`https://www.zohoapis.com/books/v3/recurringinvoices`); |
75 | for (const [k, v] of [["organization_id", organization_id]]) { |
76 | if (v !== undefined && v !== "" && k !== undefined) { |
77 | url.searchParams.append(k, v); |
78 | } |
79 | } |
80 | const response = await fetch(url, { |
81 | method: "PUT", |
82 | headers: { |
83 | "X-Unique-Identifier-Key": X_Unique_Identifier_Key, |
84 | "X-Unique-Identifier-Value": X_Unique_Identifier_Value, |
85 | ...(X_Upsert ? { "X-Upsert": X_Upsert } : {}), |
86 | "Content-Type": "application/json", |
87 | Authorization: "Zoho-oauthtoken " + auth.token, |
88 | }, |
89 | body: JSON.stringify(body), |
90 | }); |
91 | if (!response.ok) { |
92 | const text = await response.text(); |
93 | throw new Error(`${response.status} ${text}`); |
94 | } |
95 | return await response.json(); |
96 | } |
97 |
|