Finding the currently logged in JSD user with AP.user.getCurrentUser fails

Using the documentation at – User – I’ve been trying to get details of the currently logged in user - particularly the Atlassian Account ID.

The code below, cribbed from the link above…

        AP.user.getUser(function (user) {
          console.log(" 👋 user id", user.id); // fails
          console.log(" 👋 user key", user.key); // fails
          console.log(" 👋 user name", user.fullName); // fails
        });
        AP.user.getCurrentUser(function (user) {
          console.log(
            " 👋 The Atlassian Account ID is",
            user.atlassianAccountId
          ); // fails
        });
        AP.user.getTimeZone(function (timezone) {
          console.log(" 👋 timezone", timezone); // works 
        });
        AP.user.getLocale(function (locale) {
          console.log(" 👋 locale", locale); // works 
        });

…produces the following in the console:

There are no user details for the currently logged in user available.

  • Has this ever worked?
  • Is there another API to use?

Be careful with this one, it is most likely returning the default cloud timezone. Not your user’s timezone.

1 Like

No worries - I was just checking if any of those API calls worked correctly :upside_down_face:

Hi @david,

I ran a test and was able to see the atlassianAccountId field returned in the AP.user.getCurrentUser() method. I opened the chrome dev tools and entered AP.user.getCurrentUser((user) => {console.log('user:', user)}), targeting a glance panel on a JSD issue.

A couple of questions:

  1. Which type of iframe are you executing this request against?
  2. Are you logged into JSD with an Atlassian account based account (I understand non Atlassian account based accounts can also see JSD issues).

Regards,
Dugald

1 Like

Hi @dmorrow, thanks for the reply.

  • I was using a serviceDeskPortalFooters module (footer panel) so that I could access it from a single place wherever the user is in JSD
  • I was logged in as a full Atlassian account user

If I wanted to get a user identifier for either an Atlassian account user or non-Atlassian account user, should that be possible in one call?

           AP.request('/rest/api/2/myself')
            .then(data => {
                current_user = JSON.parse(data.body);
            })

This works for me

1 Like

Perfect. Thank you very much.
:upside_down_face:

1 Like