0

List users

by
Published Oct 17, 2025

List users, paginated and ordered by their name (alphabetical order).

Script gorgias Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Gorgias = {
3
  username: string;
4
  apiKey: string;
5
  domain: string;
6
};
7
/**
8
 * List users
9
 * List users, paginated and ordered by their name (alphabetical order).
10

11
 */
12
export async function main(
13
  auth: Gorgias,
14
  page: string | undefined,
15
  per_page: string | undefined,
16
  external_id: string | undefined,
17
  roles: string | undefined,
18
) {
19
  const url = new URL(`https://${auth.domain}.gorgias.com/api/users`);
20
  for (const [k, v] of [
21
    ["page", page],
22
    ["per_page", per_page],
23
    ["external_id", external_id],
24
    ["roles", roles],
25
  ]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43