0

Get User

by
Published 4 days ago

Fetch a single user by their Okta ID, login, or login shortname.

Script okta Verified

The script

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

3
/**
4
 * Get User
5
 * Fetch a single user by their Okta ID, login, or login shortname.
6
 */
7
export async function main(auth: RT.Okta, user_id: string) {
8
  const url = new URL(
9
    `${auth.org_url}/api/v1/users/${encodeURIComponent(user_id)}`
10
  )
11

12
  const response = await fetch(url, {
13
    method: "GET",
14
    headers: {
15
      Authorization: `SSWS ${auth.token}`,
16
      Accept: "application/json",
17
    },
18
  })
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26