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