1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create groups |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | body: { |
12 | user_groups?: { |
13 | created_by: { name: string; id: string }; |
14 | modified_by: { name: string; id: string }; |
15 | modified_time: string; |
16 | created_time: string; |
17 | description: string; |
18 | id: string; |
19 | name: string; |
20 | sources_count: { |
21 | territories: number; |
22 | roles: number; |
23 | groups: number; |
24 | users: { inactive: number; deleted: number; active: number }; |
25 | }; |
26 | sources: { |
27 | type: "territories" | "roles" | "users"; |
28 | source: { id: string; name: string }; |
29 | subordinates: false | true; |
30 | sub_territories: false | true; |
31 | }[]; |
32 | }[]; |
33 | }, |
34 | ) { |
35 | const url = new URL(`https://zohoapis.com/crm/v8/settings/user_groups`); |
36 |
|
37 | const response = await fetch(url, { |
38 | method: "POST", |
39 | headers: { |
40 | "Content-Type": "application/json", |
41 | Authorization: "Zoho-oauthtoken " + auth.token, |
42 | }, |
43 | body: JSON.stringify(body), |
44 | }); |
45 | if (!response.ok) { |
46 | const text = await response.text(); |
47 | throw new Error(`${response.status} ${text}`); |
48 | } |
49 | return await response.json(); |
50 | } |
51 |
|