0

Get users

by
Published Oct 17, 2025
Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Get users
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  _type:
12
    | "ActiveUsers"
13
    | "CurrentUser"
14
    | "ActiveConfirmedUsers"
15
    | "DeactiveUsers"
16
    | "NotConfirmedUsers"
17
    | "ConfirmedUsers"
18
    | undefined,
19
  page: string | undefined,
20
  per_page: string | undefined,
21
  ids: string | undefined,
22
  If_Modified_Since?: string,
23
  X_ZOHO_SERVICE?: string,
24
  X_ZCSRF_TOKEN?: string,
25
) {
26
  const url = new URL(`https://zohoapis.com/crm/v8/users`);
27
  for (const [k, v] of [
28
    ["type", _type],
29
    ["page", page],
30
    ["per_page", per_page],
31
    ["ids", ids],
32
  ]) {
33
    if (v !== undefined && v !== "" && k !== undefined) {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "GET",
39
    headers: {
40
      ...(If_Modified_Since ? { "If-Modified-Since": If_Modified_Since } : {}),
41
      ...(X_ZOHO_SERVICE ? { "X-ZOHO-SERVICE": X_ZOHO_SERVICE } : {}),
42
      ...(X_ZCSRF_TOKEN ? { "X-ZCSRF-TOKEN": X_ZCSRF_TOKEN } : {}),
43
      Authorization: "Zoho-oauthtoken " + auth.token,
44
    },
45
    body: undefined,
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53