Jira Cloud API - Getting a user in Java by email address

Patrick Fabian April 21, 2021

I'm using the Jira Cloud OpenAPI v2 in Java through this guide here: https://blog.developer.atlassian.com/update-to-jira-clouds-swagger-openapi-docs/

I'm trying to return a user by inputting his mail adress, but it doesn't work:

UsersApi usersApi = new UsersApi(apiClient);
User user = usersApi.getUser("example@mail.com", null, null, null);

 It says something about not finding anyone with that ID, I guessed that he needed the Atlassian user ID. I also tried this:

UserSearchApi userSearchApi = new UserSearchApi(apiClient);
PageBeanUser pageBeanUser = userSearchApi.findUsersByQuery("example@mail.com", 0l, 50);

But that doesn't work either.

How can I return an user when I have his e-Mail?

1 answer

0 votes
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 3, 2021

Hi @Patrick Fabian ,

Due to GDPR changes, you'll need to use a query parameter to search email addresses. An example is provided at the REST API endpoint Get User . I've copied the Java code example and modified it (on the documentation, it uses an Account ID string) to show how email might be used as the search parameter:

// This code sample uses the 'Unirest' library:
// http://unirest.io/java.html
HttpResponse<JsonNode> response = Unirest.get("https://your-domain.atlassian.com/rest/api/2/user")
.basicAuth("email@example.com", "<api_token>")
.header("Accept", "application/json")
.queryString("search", "example@mail.com")
.asJson();

System.out.println(response.getBody());

Do note that depending on a user's privacy settings on their Atlassian account, you might not be able to access the email address. Hope that helps!

Cheers,
Daniel

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events