0

Get User

by
Published Nov 2, 2023

Get a user by account ID. `expand` accepts a comma-separated list of `groups` and `applicationRoles`.

Script jira Verified

The script

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

3
/**
4
 * Get User
5
 * Get a user by account ID. `expand` accepts a comma-separated list of `groups` and `applicationRoles`.
6
 */
7
export async function main(
8
  auth: RT.Jira,
9
  account_id: string,
10
  expand: string | undefined
11
) {
12
  const url = new URL(`https://${auth.domain}.atlassian.net/rest/api/3/user`)
13
  if (expand != null && expand !== "") {
14
    url.searchParams.append("expand", expand)
15
  }
16

17
  url.searchParams.append("accountId", account_id)
18

19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
23
      Accept: "application/json",
24
    },
25
  })
26

27
  if (!response.ok) {
28
    throw new Error(`${response.status} ${await response.text()}`)
29
  }
30

31
  return await response.json()
32
}
33

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 532 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Get user
    8
     * Returns a user.
    9
    
    
    10
    Privacy controls are applied to the response based on the user's preferences. This could mean, for example, that the user's email address is hidden. See the [Profile visibility overview](https://developer.atlassian.com/cloud/jira/platform/profile-visibility/) for more details.
    11
    
    
    12
    **[Permissions](#permissions) required:** *Browse users and groups* [global permission](https://confluence.atlassian.com/x/x4dKLg).
    13
     */
    14
    export async function main(
    15
      auth: Jira,
    16
      accountId: string | undefined,
    17
      username: string | undefined,
    18
      key: string | undefined,
    19
      expand: string | undefined
    20
    ) {
    21
      const url = new URL(`https://${auth.domain}.atlassian.net/rest/api/2/user`);
    22
      for (const [k, v] of [
    23
        ["accountId", accountId],
    24
        ["username", username],
    25
        ["key", key],
    26
        ["expand", expand],
    27
      ]) {
    28
        if (v !== undefined && v !== "") {
    29
          url.searchParams.append(k, v);
    30
        }
    31
      }
    32
      const response = await fetch(url, {
    33
        method: "GET",
    34
        headers: {
    35
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    36
        },
    37
        body: undefined,
    38
      });
    39
      if (!response.ok) {
    40
        const text = await response.text();
    41
        throw new Error(`${response.status} ${text}`);
    42
      }
    43
      return await response.json();
    44
    }
    45