1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a Recurring Invoice |
7 | * Creating a new recurring invoice. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | body: { |
13 | recurrence_name: string; |
14 | reference_number?: string; |
15 | customer_id: string; |
16 | currency_id?: string; |
17 | contact_persons?: string[]; |
18 | place_of_supply?: string; |
19 | vat_treatment?: string; |
20 | gst_treatment?: string; |
21 | tax_treatment?: string; |
22 | is_reverse_charge_applied?: false | true; |
23 | cfdi_usage?: string; |
24 | allow_partial_payments?: false | true; |
25 | gst_no?: string; |
26 | start_date?: string; |
27 | end_date?: string; |
28 | recurrence_frequency: "weeks"; |
29 | repeat_every?: number; |
30 | location_id?: string; |
31 | line_items?: { |
32 | line_item_id?: string; |
33 | quantity?: number; |
34 | name?: string; |
35 | item_total?: number; |
36 | product_type?: string; |
37 | hsn_or_sac?: string; |
38 | sat_item_key_code?: string; |
39 | unitkey_code?: string; |
40 | tags?: { tag_id?: string; tag_option_id?: string }[]; |
41 | location_id?: string; |
42 | tax_id?: {}; |
43 | tds_tax_id?: string; |
44 | tax_treatment_code?: string; |
45 | project_id?: string; |
46 | header_name?: string; |
47 | }[]; |
48 | tax_id?: {}; |
49 | custom_fields?: { value?: string; label?: string; data_type?: string }[]; |
50 | email?: string; |
51 | billing_address?: { |
52 | address?: string; |
53 | street2?: string; |
54 | city?: string; |
55 | state?: string; |
56 | zip?: string; |
57 | country?: string; |
58 | fax?: string; |
59 | }; |
60 | shipping_address?: { |
61 | address?: string; |
62 | city?: string; |
63 | state?: string; |
64 | zip?: string; |
65 | country?: string; |
66 | fax?: string; |
67 | }; |
68 | avatax_use_code?: string; |
69 | avatax_exempt_no?: string; |
70 | template_id?: string; |
71 | payment_terms?: number; |
72 | payment_terms_label?: string; |
73 | tax_authority_id?: string; |
74 | tax_exemption_id?: string; |
75 | exchange_rate?: string; |
76 | payment_options?: { |
77 | payment_gateways?: { |
78 | configured?: false | true; |
79 | additional_field1?: string; |
80 | gateway_name?: string; |
81 | }[]; |
82 | }; |
83 | discount?: string; |
84 | is_discount_before_tax?: false | true; |
85 | discount_type?: string; |
86 | is_inclusive_tax?: false | true; |
87 | item_id?: string; |
88 | name?: string; |
89 | description?: string; |
90 | rate?: number; |
91 | quantity?: number; |
92 | unit?: string; |
93 | avatax_tax_code?: string; |
94 | salesperson_name?: string; |
95 | shipping_charge?: number; |
96 | adjustment?: number; |
97 | adjustment_description?: string; |
98 | }, |
99 | ) { |
100 | const url = new URL(`https://www.zohoapis.com/books/v3/recurringinvoices`); |
101 | for (const [k, v] of [["organization_id", organization_id]]) { |
102 | if (v !== undefined && v !== "" && k !== undefined) { |
103 | url.searchParams.append(k, v); |
104 | } |
105 | } |
106 | const response = await fetch(url, { |
107 | method: "POST", |
108 | headers: { |
109 | "Content-Type": "application/json", |
110 | Authorization: "Zoho-oauthtoken " + auth.token, |
111 | }, |
112 | body: JSON.stringify(body), |
113 | }); |
114 | if (!response.ok) { |
115 | const text = await response.text(); |
116 | throw new Error(`${response.status} ${text}`); |
117 | } |
118 | return await response.json(); |
119 | } |
120 |
|