1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get download inline images |
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 | ) { |
17 | const url = new URL( |
18 | `https://zohoapis.com/crm/v8/${_module}/${record_id}/Emails/actions/download_inline_images`, |
19 | ); |
20 | for (const [k, v] of [ |
21 | ["user_id", user_id], |
22 | ["message_id", message_id], |
23 | ["id", id], |
24 | ]) { |
25 | if (v !== undefined && v !== "" && k !== undefined) { |
26 | url.searchParams.append(k, v); |
27 | } |
28 | } |
29 | const response = await fetch(url, { |
30 | method: "GET", |
31 | headers: { |
32 | Authorization: "Zoho-oauthtoken " + auth.token, |
33 | }, |
34 | body: undefined, |
35 | }); |
36 | if (!response.ok) { |
37 | const text = await response.text(); |
38 | throw new Error(`${response.status} ${text}`); |
39 | } |
40 | return await response.text(); |
41 | } |
42 |
|