REST API to get currently logged in user's username

Dishant Sharma
Contributor
October 3, 2022

I am using confluence server 7.13.7. I want a REST API to get the currently logged-in user's username so I can use it in other API calls to fetch more details about the user further.

 

I know of a way by using the snippet:

 

var userFullname = $("#user-menu-link").attr("title");

to get the current user's username. But, in my use case; I am in need of a REST API. 

1 answer

0 votes
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 4, 2022
Dishant Sharma
Contributor
October 4, 2022

@Alex Koxaras _Relational_ thanks for the reply. Yes, I tried it and it is working perfectly fine. But, in my use case, I want to make an API call where I will not have direct access to the confluence interface and I will only have the required admin credentials. So, I was looking to make an API call where I can pass the admin token and other details and the user's mail (I will have access to the user's mail) and it will fetch down the username of that particular user.

Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 4, 2022

That doesn't make sense, you said you wanted the current user's username. I don't see how you can achieve that when you are another person.

How can you make an API call when you can't "access confluence interface". It's web based application and so is REST, same http protocol.

What it sounds like now is that you are trying to simply "get username found by email address over REST", which Confluence doesn't have, you can search for users by usernames/userkeys, but not by email (https://docs.atlassian.com/ConfluenceServer/rest/7.12.3/#api/user). To do so you'd need to likely implement your own endpoint making use of either cache or indexed db table (I assume the column is not indexed by default), otherwise the performance would be horrible on large instances.

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events