1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get email composer default settings |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | _type: "default" | "emailin" | "mass_mail" | undefined, |
12 | ) { |
13 | const url = new URL(`https://zohoapis.com/crm/email/v8/settings/compose`); |
14 | for (const [k, v] of [["type", _type]]) { |
15 | if (v !== undefined && v !== "" && k !== undefined) { |
16 | url.searchParams.append(k, v); |
17 | } |
18 | } |
19 | const response = await fetch(url, { |
20 | method: "GET", |
21 | headers: { |
22 | Authorization: "Zoho-oauthtoken " + auth.token, |
23 | }, |
24 | body: undefined, |
25 | }); |
26 | if (!response.ok) { |
27 | const text = await response.text(); |
28 | throw new Error(`${response.status} ${text}`); |
29 | } |
30 | return await response.json(); |
31 | } |
32 |
|