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