Edits history of script submission #22825 for ' Get Current User (confluence)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Current User
     * Returns the profile of the user that the API token authenticates as (account ID, display name, email).
     */
    export async function main(auth: RT.Confluence) {
      const base = auth.baseUrl.replace(/\/$/, "")
      const url = new URL(`${base}/wiki/rest/api/user/current`)
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.email}:${auth.apiToken}`),
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 4 hours ago