0

Find users and groups

by
Published Nov 2, 2023

Returns a list of users and groups matching a string.

Script jira
  • Submitted by hugo697 Typescript (fetch-only)
    Created 527 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Find users and groups
    8
     * Returns a list of users and groups matching a string.
    9
     */
    10
    export async function main(
    11
      auth: Jira,
    12
      query: string | undefined,
    13
      maxResults: string | undefined,
    14
      showAvatar: string | undefined,
    15
      fieldId: string | undefined,
    16
      projectId: string | undefined,
    17
      issueTypeId: string | undefined,
    18
      avatarSize:
    19
        | "xsmall"
    20
        | "xsmall@2x"
    21
        | "xsmall@3x"
    22
        | "small"
    23
        | "small@2x"
    24
        | "small@3x"
    25
        | "medium"
    26
        | "medium@2x"
    27
        | "medium@3x"
    28
        | "large"
    29
        | "large@2x"
    30
        | "large@3x"
    31
        | "xlarge"
    32
        | "xlarge@2x"
    33
        | "xlarge@3x"
    34
        | "xxlarge"
    35
        | "xxlarge@2x"
    36
        | "xxlarge@3x"
    37
        | "xxxlarge"
    38
        | "xxxlarge@2x"
    39
        | "xxxlarge@3x"
    40
        | undefined,
    41
      caseInsensitive: string | undefined,
    42
      excludeConnectAddons: string | undefined
    43
    ) {
    44
      const url = new URL(
    45
        `https://${auth.domain}.atlassian.net/rest/api/2/groupuserpicker`
    46
      );
    47
      for (const [k, v] of [
    48
        ["query", query],
    49
        ["maxResults", maxResults],
    50
        ["showAvatar", showAvatar],
    51
        ["fieldId", fieldId],
    52
        ["projectId", projectId],
    53
        ["issueTypeId", issueTypeId],
    54
        ["avatarSize", avatarSize],
    55
        ["caseInsensitive", caseInsensitive],
    56
        ["excludeConnectAddons", excludeConnectAddons],
    57
      ]) {
    58
        if (v !== undefined && v !== "") {
    59
          url.searchParams.append(k, v);
    60
        }
    61
      }
    62
      const response = await fetch(url, {
    63
        method: "GET",
    64
        headers: {
    65
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    66
        },
    67
        body: undefined,
    68
      });
    69
      if (!response.ok) {
    70
        const text = await response.text();
    71
        throw new Error(`${response.status} ${text}`);
    72
      }
    73
      return await response.json();
    74
    }
    75