1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a retainerinvoice |
7 | * Create a retainer invoice for your customer. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | ignore_auto_number_generation: string | undefined, |
13 | body: { |
14 | customer_id: string; |
15 | reference_number?: string; |
16 | date?: string; |
17 | contact_persons?: string[]; |
18 | custom_fields?: { |
19 | index?: number; |
20 | show_on_pdf?: false | true; |
21 | value?: string; |
22 | label?: string; |
23 | }[]; |
24 | notes?: string; |
25 | terms?: string; |
26 | location_id?: string; |
27 | line_items: { description?: string; item_order?: number; rate?: number }[]; |
28 | payment_options?: { |
29 | payment_gateways?: { |
30 | configured?: false | true; |
31 | additional_field1?: string; |
32 | gateway_name?: string; |
33 | }[]; |
34 | }; |
35 | template_id?: string; |
36 | place_of_supply?: string; |
37 | }, |
38 | ) { |
39 | const url = new URL(`https://www.zohoapis.com/inventory/v1/retainerinvoices`); |
40 | for (const [k, v] of [ |
41 | ["organization_id", organization_id], |
42 | ["ignore_auto_number_generation", ignore_auto_number_generation], |
43 | ]) { |
44 | if (v !== undefined && v !== "" && k !== undefined) { |
45 | url.searchParams.append(k, v); |
46 | } |
47 | } |
48 | const response = await fetch(url, { |
49 | method: "POST", |
50 | headers: { |
51 | "Content-Type": "application/json", |
52 | Authorization: "Zoho-oauthtoken " + auth.token, |
53 | }, |
54 | body: JSON.stringify(body), |
55 | }); |
56 | if (!response.ok) { |
57 | const text = await response.text(); |
58 | throw new Error(`${response.status} ${text}`); |
59 | } |
60 | return await response.json(); |
61 | } |
62 |
|