0

Get Current User

by
Published today

Returns the profile of the user that the API token authenticates as.

Script confluence Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 3 hours ago
1
//native
2

3
/**
4
 * Get Current User
5
 * Returns the profile of the user that the API token authenticates as (account ID, display name, email).
6
 */
7
export async function main(auth: RT.Confluence) {
8
  const base = auth.baseUrl.replace(/\/$/, "")
9
  const url = new URL(`${base}/wiki/rest/api/user/current`)
10

11
  const response = await fetch(url, {
12
    method: "GET",
13
    headers: {
14
      Authorization: "Basic " + btoa(`${auth.email}:${auth.apiToken}`),
15
      Accept: "application/json",
16
    },
17
  })
18

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

23
  return await response.json()
24
}
25