1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get download attachments details |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | _module: string, |
12 | record_id: string, |
13 | user_id: string | undefined, |
14 | message_id: string | undefined, |
15 | id: string | undefined, |
16 | name: string | undefined, |
17 | ) { |
18 | const url = new URL( |
19 | `https://zohoapis.com/crm/v8/${_module}/${record_id}/Emails/actions/download_attachments`, |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["user_id", user_id], |
23 | ["message_id", message_id], |
24 | ["id", id], |
25 | ["name", name], |
26 | ]) { |
27 | if (v !== undefined && v !== "" && k !== undefined) { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "GET", |
33 | headers: { |
34 | Authorization: "Zoho-oauthtoken " + auth.token, |
35 | }, |
36 | body: undefined, |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.text(); |
43 | } |
44 |
|