Edits history of script submission #23369 for ' Get User (jira)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get User
     * Get a user by account ID. `expand` accepts a comma-separated list of `groups` and `applicationRoles`.
     */
    export async function main(
      auth: RT.Jira,
      account_id: string,
      expand: string | undefined
    ) {
      const url = new URL(`https://${auth.domain}.atlassian.net/rest/api/3/user`)
      if (expand != null && expand !== "") {
        url.searchParams.append("expand", expand)
      }
    
      url.searchParams.append("accountId", account_id)
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 8 days ago