0

Get Current User

by
Published Nov 2, 2023

Get the account the credentials belong to: account ID, display name, email, time zone. A quick way to check the resource works.

Script jira Verified

The script

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

3
/**
4
 * Get Current User
5
 * Get the account the credentials belong to: account ID, display name, email, time zone. A quick way to check the resource works.
6
 */
7
export async function main(auth: RT.Jira, expand: string | undefined) {
8
  const url = new URL(`https://${auth.domain}.atlassian.net/rest/api/3/myself`)
9
  if (expand != null && expand !== "") {
10
    url.searchParams.append("expand", expand)
11
  }
12

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

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

25
  return await response.json()
26
}
27

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 current user
    8
     * Returns details for the current user.
    9
    
    
    10
    **[Permissions](#permissions) required:** Permission to access Jira.
    11
     */
    12
    export async function main(auth: Jira, expand: string | undefined) {
    13
      const url = new URL(`https://${auth.domain}.atlassian.net/rest/api/2/myself`);
    14
      for (const [k, v] of [["expand", expand]]) {
    15
        if (v !== undefined && v !== "") {
    16
          url.searchParams.append(k, v);
    17
        }
    18
      }
    19
      const response = await fetch(url, {
    20
        method: "GET",
    21
        headers: {
    22
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    23
        },
    24
        body: undefined,
    25
      });
    26
      if (!response.ok) {
    27
        const text = await response.text();
    28
        throw new Error(`${response.status} ${text}`);
    29
      }
    30
      return await response.json();
    31
    }
    32