1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Change users status |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | portal_name: string, |
12 | user_type_id: string, |
13 | user_id: string, |
14 | active: string | undefined, |
15 | ) { |
16 | const url = new URL( |
17 | `https://zohoapis.com/crm/v8/settings/portals/${portal_name}/user_type/${user_type_id}/users/${user_id}/actions/change_status`, |
18 | ); |
19 | for (const [k, v] of [["active", active]]) { |
20 | if (v !== undefined && v !== "" && k !== undefined) { |
21 | url.searchParams.append(k, v); |
22 | } |
23 | } |
24 | const response = await fetch(url, { |
25 | method: "PUT", |
26 | headers: { |
27 | Authorization: "Zoho-oauthtoken " + auth.token, |
28 | }, |
29 | body: undefined, |
30 | }); |
31 | if (!response.ok) { |
32 | const text = await response.text(); |
33 | throw new Error(`${response.status} ${text}`); |
34 | } |
35 | return await response.json(); |
36 | } |
37 |
|