1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update map dependency |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | layout_id: string, |
12 | dependency_id: string, |
13 | _module: string | undefined, |
14 | body: { |
15 | map_dependency?: { |
16 | parent?: { api_name?: string; id?: string }; |
17 | child?: { api_name?: string; id?: string }; |
18 | pick_list_values?: { |
19 | id?: string; |
20 | actual_value?: string; |
21 | display_value?: string; |
22 | maps?: { |
23 | id?: string; |
24 | actual_value?: string; |
25 | display_value?: string; |
26 | _delete?: false | true; |
27 | }[]; |
28 | }[]; |
29 | internal?: false | true; |
30 | active?: false | true; |
31 | id?: string; |
32 | source?: number; |
33 | category?: number; |
34 | sub_module?: { api_name?: string; id?: string }; |
35 | }[]; |
36 | }, |
37 | ) { |
38 | const url = new URL( |
39 | `https://zohoapis.com/crm/v8/settings/layouts/${layout_id}/map_dependency/${dependency_id}`, |
40 | ); |
41 | for (const [k, v] of [["module", _module]]) { |
42 | if (v !== undefined && v !== "" && k !== undefined) { |
43 | url.searchParams.append(k, v); |
44 | } |
45 | } |
46 | const response = await fetch(url, { |
47 | method: "PUT", |
48 | headers: { |
49 | "Content-Type": "application/json", |
50 | Authorization: "Zoho-oauthtoken " + auth.token, |
51 | }, |
52 | body: JSON.stringify(body), |
53 | }); |
54 | if (!response.ok) { |
55 | const text = await response.text(); |
56 | throw new Error(`${response.status} ${text}`); |
57 | } |
58 | return await response.json(); |
59 | } |
60 |
|