0

List Users

by
Published 4 days ago

List users in your org, optionally filtered by a SCIM filter, free-text search, or a startsWith query.

Script okta Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
2

3
/**
4
 * List Users
5
 * List users in your org. Filter with a SCIM `filter` expression, a free-text `search`, or a simple `q` startsWith match on name/email. Page with `limit` (default 200) and the `after` cursor from the previous response's Link header.
6
 */
7
export async function main(
8
  auth: RT.Okta,
9
  q: string | undefined,
10
  filter: string | undefined,
11
  search: string | undefined,
12
  limit: number | undefined,
13
  after: string | undefined
14
) {
15
  const url = new URL(`${auth.org_url}/api/v1/users`)
16
  if (q !== undefined && q !== "") url.searchParams.append("q", q)
17
  if (filter !== undefined && filter !== "")
18
    url.searchParams.append("filter", filter)
19
  if (search !== undefined && search !== "")
20
    url.searchParams.append("search", search)
21
  if (limit !== undefined) url.searchParams.append("limit", String(limit))
22
  if (after !== undefined && after !== "")
23
    url.searchParams.append("after", after)
24

25
  const response = await fetch(url, {
26
    method: "GET",
27
    headers: {
28
      Authorization: `SSWS ${auth.token}`,
29
      Accept: "application/json",
30
    },
31
  })
32

33
  if (!response.ok) {
34
    throw new Error(`${response.status} ${await response.text()}`)
35
  }
36

37
  return await response.json()
38
}
39