1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a Contact |
7 | * Create a contact with given information. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | body: { |
13 | contact_name: string; |
14 | company_name?: string; |
15 | payment_terms?: number; |
16 | currency_id?: string; |
17 | website?: string; |
18 | contact_type?: string; |
19 | custom_fields?: { value?: string; index?: number }[]; |
20 | opening_balances?: { |
21 | location_id?: string; |
22 | exchange_rate?: number; |
23 | opening_balance_amount?: number; |
24 | }[]; |
25 | billing_address?: { |
26 | attention?: string; |
27 | address?: string; |
28 | street2?: string; |
29 | city?: string; |
30 | state?: string; |
31 | zip?: string; |
32 | country?: string; |
33 | }; |
34 | shipping_address?: { |
35 | attention?: string; |
36 | address?: string; |
37 | street2?: string; |
38 | city?: string; |
39 | state?: string; |
40 | zip?: string; |
41 | country?: string; |
42 | }; |
43 | contact_persons?: { |
44 | salutation?: string; |
45 | first_name?: string; |
46 | last_name?: string; |
47 | email?: string; |
48 | phone?: string; |
49 | mobile?: string; |
50 | is_primary_contact?: false | true; |
51 | }[]; |
52 | default_templates?: { |
53 | invoice_template_id?: string; |
54 | invoice_template_name?: string; |
55 | estimate_template_id?: string; |
56 | estimate_template_name?: string; |
57 | creditnote_template_id?: string; |
58 | creditnote_template_name?: string; |
59 | invoice_email_template_id?: string; |
60 | invoice_email_template_name?: string; |
61 | estimate_email_template_id?: string; |
62 | estimate_email_template_name?: string; |
63 | creditnote_email_template_id?: string; |
64 | creditnote_email_template_name?: string; |
65 | }; |
66 | language_code?: string; |
67 | notes?: string; |
68 | vat_reg_no?: string; |
69 | tax_reg_no?: string; |
70 | country_code?: string; |
71 | vat_treatment?: string; |
72 | tax_treatment?: string; |
73 | tax_regime?: string; |
74 | legal_name?: string; |
75 | is_tds_registered?: false | true; |
76 | avatax_exempt_no?: string; |
77 | avatax_use_code?: string; |
78 | tax_exemption_id?: string; |
79 | tax_authority_id?: string; |
80 | tax_id?: false | true; |
81 | is_taxable?: false | true; |
82 | facebook?: string; |
83 | twitter?: string; |
84 | place_of_contact?: string; |
85 | gst_no?: string; |
86 | gst_treatment?: string; |
87 | tax_authority_name?: string; |
88 | tax_exemption_code?: string; |
89 | }, |
90 | ) { |
91 | const url = new URL(`https://www.zohoapis.com/inventory/v1/contacts`); |
92 | for (const [k, v] of [["organization_id", organization_id]]) { |
93 | if (v !== undefined && v !== "" && k !== undefined) { |
94 | url.searchParams.append(k, v); |
95 | } |
96 | } |
97 | const response = await fetch(url, { |
98 | method: "POST", |
99 | headers: { |
100 | "Content-Type": "application/json", |
101 | Authorization: "Zoho-oauthtoken " + auth.token, |
102 | }, |
103 | body: JSON.stringify(body), |
104 | }); |
105 | if (!response.ok) { |
106 | const text = await response.text(); |
107 | throw new Error(`${response.status} ${text}`); |
108 | } |
109 | return await response.json(); |
110 | } |
111 |
|