1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Merge records |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | masterrecordid: string, |
12 | _module: string, |
13 | body: { |
14 | merge: { |
15 | job_id?: string; |
16 | status?: string; |
17 | data: { |
18 | _fields?: { api_name?: string; _data?: { id: string }[] }[]; |
19 | id?: string; |
20 | }[]; |
21 | master_record_fields: { api_name: string; _data: { id: string }[] }[]; |
22 | }[]; |
23 | }, |
24 | ) { |
25 | const url = new URL( |
26 | `https://zohoapis.com/crm/v8/${_module}/${masterrecordid}/actions/merge`, |
27 | ); |
28 |
|
29 | const response = await fetch(url, { |
30 | method: "POST", |
31 | headers: { |
32 | "Content-Type": "application/json", |
33 | Authorization: "Zoho-oauthtoken " + auth.token, |
34 | }, |
35 | body: JSON.stringify(body), |
36 | }); |
37 | if (!response.ok) { |
38 | const text = await response.text(); |
39 | throw new Error(`${response.status} ${text}`); |
40 | } |
41 | return await response.json(); |
42 | } |
43 |
|