Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,017
Community Members
 
Community Events
168
Community Groups

Find a user by email address in Confluence and Bitbucket using Java API/SDK

Hi everyone,

 

I'm writing a plugin for Jira/Bitbucket/Confluence Server, and for some reasons, I need to get a user by searching its email address, then I try to find an API like this:

User user = userService.getUserByEmail(givenEmail)

I eventually found one such API in Jira:

Iterable<ApplicationUser> users = ComponentAccessor.getUserSearchService().findUsersByEmail(email);

But I wonder if there‘re any APIs like that in Confluence or Bitbucket? Or any other APIs that I can use to search users by email address?

 

Thanks so much. 

 

1 answer

1 accepted

0 votes
Answer accepted

I just found such an API in Bitbucket:

ComponentLocator.getComponent(com.atlassian.bitbucket.user.UserService.class).findUserByEmail(email)

And I found it for Confluence:

bucket.user.UserAccessor#getUsersByEmail

Although it's deprecated, but we can refer its implemention. 

(For Confluence) Such as:

/**
* @param email
* @return
* @see DefaultUserAccessor#getUsersByEmail(String)
*/
private SearchResult getUsersByEmail(String email) {
if (!TextUtils.stringSet(email)) {
return new DefaultSearchResult();
} else {
SearchResult<com.atlassian.user.User> results = null;
EmailTermQuery emailQuery = new EmailTermQuery(email);

try {
results = entityQueryParser.findUsers(emailQuery);
results = ComponentLocator.getComponent(EntityQueryParser.class).findUsers(emailQuery);
} catch (EntityException var5) {
log.error(var5.getMessage());
}

return results;
}
}

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events