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