1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a contact person |
7 | * Update details of an existing contact person. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | contact_person_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | contact_id: string; |
15 | salutation?: string; |
16 | first_name: string; |
17 | last_name?: string; |
18 | email?: string; |
19 | phone?: string; |
20 | mobile?: string; |
21 | skype?: string; |
22 | designation?: string; |
23 | department?: string; |
24 | enable_portal?: false | true; |
25 | }, |
26 | ) { |
27 | const url = new URL( |
28 | `https://www.zohoapis.com/inventory/v1/contacts/contactpersons/${contact_person_id}`, |
29 | ); |
30 | for (const [k, v] of [["organization_id", organization_id]]) { |
31 | if (v !== undefined && v !== "" && k !== undefined) { |
32 | url.searchParams.append(k, v); |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: "PUT", |
37 | headers: { |
38 | "Content-Type": "application/json", |
39 | Authorization: "Zoho-oauthtoken " + auth.token, |
40 | }, |
41 | body: JSON.stringify(body), |
42 | }); |
43 | if (!response.ok) { |
44 | const text = await response.text(); |
45 | throw new Error(`${response.status} ${text}`); |
46 | } |
47 | return await response.json(); |
48 | } |
49 |
|