1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update related records |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | module_api_name: string, |
12 | record_id: string, |
13 | related_list_api_name: string, |
14 | body: { |
15 | data?: { |
16 | id?: string; |
17 | Created_By?: { name: string; id: string; email?: string }; |
18 | Created_Time?: string; |
19 | Modified_By?: { name: string; id: string; email?: string }; |
20 | Modified_Time?: string; |
21 | Tag?: { |
22 | name: string; |
23 | color_code: |
24 | | "#57B1FD" |
25 | | "#879BFC" |
26 | | "#658BA8" |
27 | | "#FD87BD" |
28 | | "#969696" |
29 | | "#F48435" |
30 | | "#1DB9B4" |
31 | | "#E7A826" |
32 | | "#63C57E" |
33 | | "#F17574" |
34 | | "#D297EE" |
35 | | "#A8C026" |
36 | | "#B88562"; |
37 | created_time: string; |
38 | modified_time: string; |
39 | modified_by: { name: string; id: string; email?: string }; |
40 | created_by: { name: string; id: string; email?: string }; |
41 | id: string; |
42 | }[]; |
43 | name?: string; |
44 | }[]; |
45 | }, |
46 | X_EXTERNAL?: string, |
47 | ) { |
48 | const url = new URL( |
49 | `https://zohoapis.com/crm/v8/${module_api_name}/${record_id}/${related_list_api_name}`, |
50 | ); |
51 |
|
52 | const response = await fetch(url, { |
53 | method: "PUT", |
54 | headers: { |
55 | ...(X_EXTERNAL ? { "X-EXTERNAL": X_EXTERNAL } : {}), |
56 | "Content-Type": "application/json", |
57 | Authorization: "Zoho-oauthtoken " + auth.token, |
58 | }, |
59 | body: JSON.stringify(body), |
60 | }); |
61 | if (!response.ok) { |
62 | const text = await response.text(); |
63 | throw new Error(`${response.status} ${text}`); |
64 | } |
65 | return await response.json(); |
66 | } |
67 |
|