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