Getting current users accountId

Hi

I needt current users accountId.
I am trying to get it from ‘myself’ resurse for currently logged in user by jira cloud rest api, but i can’t find a way to make it happen.

AtlassianHostRestClients.authenticatedAsAddon().getForObject(urir, String.class);
returns the addon information and
AtlassianHostRestClients.authenticatedAsHostActor().getForObject(uri, String.class);
returns an error:

Was asked to authenticate the rest client as the current acting user on the host, but none could be inferred from the current request

Is there a better way to find currently logged in users accountId?

Hi @TaaviTilgre,

This sounds a lot like you are using atlassian-connect-spring-boot for your app? As mentioned in the README, you can let it inject an AtlassianHostUser into your REST Controller methods:

@Controller
public class HelloWorld {

    @RequestMapping(value = "/hello-world", method = RequestMethod.GET)
    @ResponseBody
    public String helloWorld(@AuthenticationPrincipal AtlassianHostUser hostUser) {
        return "hello-world";
    }
}

Hope this helps!

Cheers,
Sven

2 Likes