JRJC: Getting User's Display Name from the User ID

Does anyone know the easiest way to get the current user’s Display name using JRJC (Java REST Jira Client) or JS?

Currently I was able to get the user’s ID from the AP javascript function helper with the following code:

AP.user.getCurrentUser(function(user) {
        currentUserId = user.atlassianAccountId;
        console.log("The Atlassian Account ID is", currentUserId);
    });

Now that I have the ID of the current user, I have passed it back to Springboot to have the Java REST Jira Client attempt to use the ID to find the current user’s display name, but I’m having a hard time trying to find the correct path forward here.

Any help?

Ty in advance!

Old question, but since I’m investigating the same issue I’m gonna write what I found.

Seems there are 2 possibilities:

  1. Use get user api as described here.
  2. Use find user api as described here.

Both of the apis, require the user to have Browse users and groups global permission.
This seems odd to me, that to get currently logged in user name in the browser (so basically my own name) I need to have browse user premission.
Perhaps I’m missing some dangers here (related to GDPR or similar), but I would expect AP.user.getCurrentUser to return also current user name, as it is my name.

After working with it, below code seems to work:

AP.user.getCurrentUser(function(user) {
  AP.request({
    url: `/rest/api/3/user?accountId=${user.atlassianAccountId}`,
    type: 'GET',
    contentType: 'Application/json',
    success: function(data){...},
    error: function(xhr, statusText, errorThrown){...}
  });
});

If you can run the request in the front end (ie, as the end user), consider using the /rest/api/2/myself API. It has lower permission requirements. Then pass the displayName, etc to the backend.

https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-myself/#api-rest-api-2-myself-get

Regards,
Chris

1 Like