1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Mass update records |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | module_api_name: string, |
12 | body: { |
13 | data?: { |
14 | id?: string; |
15 | Created_By?: { name: string; id: string; email?: string }; |
16 | Created_Time?: string; |
17 | Modified_By?: { name: string; id: string; email?: string }; |
18 | Modified_Time?: string; |
19 | Tag?: { |
20 | name: string; |
21 | color_code: |
22 | | "#57B1FD" |
23 | | "#879BFC" |
24 | | "#658BA8" |
25 | | "#FD87BD" |
26 | | "#969696" |
27 | | "#F48435" |
28 | | "#1DB9B4" |
29 | | "#E7A826" |
30 | | "#63C57E" |
31 | | "#F17574" |
32 | | "#D297EE" |
33 | | "#A8C026" |
34 | | "#B88562"; |
35 | created_time: string; |
36 | modified_time: string; |
37 | modified_by: { name: string; id: string; email?: string }; |
38 | created_by: { name: string; id: string; email?: string }; |
39 | id: string; |
40 | }[]; |
41 | name?: string; |
42 | }[]; |
43 | cvid?: string; |
44 | ids?: string[]; |
45 | territory?: { id?: string; include_child?: false | true }; |
46 | over_write?: false | true; |
47 | criteria?: { |
48 | comparator?: |
49 | | "in" |
50 | | "greater_equal" |
51 | | "starts_with" |
52 | | "equal" |
53 | | "contains" |
54 | | "ends_with" |
55 | | "not_contains" |
56 | | "not_equal" |
57 | | "not_in" |
58 | | "greater_than" |
59 | | "less_than" |
60 | | "not_between" |
61 | | "less_equal" |
62 | | "between"; |
63 | field?: string; |
64 | value?: {}; |
65 | group_operator?: "or" | "and"; |
66 | group?: {}[]; |
67 | }[]; |
68 | }, |
69 | ) { |
70 | const url = new URL( |
71 | `https://zohoapis.com/crm/v8/${module_api_name}/actions/mass_update`, |
72 | ); |
73 |
|
74 | const response = await fetch(url, { |
75 | method: "POST", |
76 | headers: { |
77 | "Content-Type": "application/json", |
78 | Authorization: "Zoho-oauthtoken " + auth.token, |
79 | }, |
80 | body: JSON.stringify(body), |
81 | }); |
82 | if (!response.ok) { |
83 | const text = await response.text(); |
84 | throw new Error(`${response.status} ${text}`); |
85 | } |
86 | return await response.json(); |
87 | } |
88 |
|