1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update assignment rules |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | _module: string | undefined, |
12 | body: { |
13 | assignment_rules: { |
14 | created_time: string; |
15 | modified_time: string; |
16 | default_assignee: { name: string; id: string }; |
17 | api_name: string; |
18 | modified_by: { zuid: number; name: string; id: string; email?: string }; |
19 | created_by: { zuid: number; name: string; id: string; email?: string }; |
20 | id: string; |
21 | name: string; |
22 | module: { |
23 | api_name: string; |
24 | id: string; |
25 | module_name?: string; |
26 | module?: string; |
27 | }; |
28 | description: string; |
29 | }[]; |
30 | }, |
31 | ) { |
32 | const url = new URL( |
33 | `https://zohoapis.com/crm/v8/settings/automation/assignment_rules`, |
34 | ); |
35 | for (const [k, v] of [["module", _module]]) { |
36 | if (v !== undefined && v !== "" && k !== undefined) { |
37 | url.searchParams.append(k, v); |
38 | } |
39 | } |
40 | const response = await fetch(url, { |
41 | method: "PUT", |
42 | headers: { |
43 | "Content-Type": "application/json", |
44 | Authorization: "Zoho-oauthtoken " + auth.token, |
45 | }, |
46 | body: JSON.stringify(body), |
47 | }); |
48 | if (!response.ok) { |
49 | const text = await response.text(); |
50 | throw new Error(`${response.status} ${text}`); |
51 | } |
52 | return await response.json(); |
53 | } |
54 |
|