1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create duplicate check preference |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | _module: string | undefined, |
12 | body: { |
13 | duplicate_check_preference: { |
14 | type: "converted_records" | "mapped_module_records"; |
15 | type_configurations: { |
16 | field_mappings: { |
17 | current_field: { id: string; api_name: string; name: string }; |
18 | mapped_field: { id: string; api_name: string; name: string }; |
19 | }[]; |
20 | mapped_module: { id: string; api_name: string; name: string }; |
21 | }[]; |
22 | }; |
23 | }, |
24 | ) { |
25 | const url = new URL( |
26 | `https://zohoapis.com/crm/v8/settings/duplicate_check_preference`, |
27 | ); |
28 | for (const [k, v] of [["module", _module]]) { |
29 | if (v !== undefined && v !== "" && k !== undefined) { |
30 | url.searchParams.append(k, v); |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: "POST", |
35 | headers: { |
36 | "Content-Type": "application/json", |
37 | Authorization: "Zoho-oauthtoken " + auth.token, |
38 | }, |
39 | body: JSON.stringify(body), |
40 | }); |
41 | if (!response.ok) { |
42 | const text = await response.text(); |
43 | throw new Error(`${response.status} ${text}`); |
44 | } |
45 | return await response.json(); |
46 | } |
47 |
|