Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get user email address using BitBucket API?

Ramesh Kannan March 23, 2016

I'm an administrator of a Bitbucket account. Under my account I've more than 50 repositories and 5 more groups. 

I'm using Bitbucket API to get list of open pull requests. I want to notify the reviewers to take necessary action on the OPEN pull request. For sending notification I need the reviewers email addresses, but I cannot find any API for getting email address from username.

Is it possible to get email addresses of user by using their username? 

4 answers

13 votes
Steven Combs January 14, 2019

This is a very basic repository administration feature that most teams want

5 votes
Vitaly Ketsenko February 14, 2019

This is so stupid, I added all users by emails - so I know emails, they have created accounts and now I can't see those emails, I have to ask each one what email did they use and some don't even remember, and of course it's hard to find it in chat with every user because I added them several months ago

Stephen Estrada March 12, 2020

+1

Like # people like this
Saurabh Vajpayee July 13, 2020

+1

Like Disruptive Effects likes this
1 vote
Alexandr Marchenko May 17, 2020

There is an workaround for those who also using jira

Here is a powershell snippet:

# bitbucket users
$org = "contoso"
$username = "username@contoso.com"
$password = "********************"
$headers = @{ Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username):$($password)")) }

$bitbucket = Invoke-RestMethod -Headers $headers -Uri "https://api.bitbucket.org/2.0/workspaces/$org/members?pagelen=100" | Select-Object -ExpandProperty values | Select-Object -ExpandProperty user | Select-Object display_name, nickname, account_id

# jira users
$org = "contoso"
$username = "username@contoso.com"
$password = "********************"
$headers = @{ Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username):$($password)"))

$jira = Invoke-RestMethod -Headers $headers -Uri "https://$org.atlassian.net/rest/api/3/users/search?maxResults=500"
$jira = $jira | Group-Object accountId -AsHashTable


# join
$bitbucket | Select-Object display_name, @{n='email';e={ $jira[$_.account_id][0].emailAddress }}

Which will print your bitbucket users and their emails

How it works:

  • from bitbucket we are retrieving accountId which in most cases same for both bitbucket and jira (but not always)
  • from jira we are retrieving users with emails
  • join both collections by account id field
  • profit
mient-jan October 22, 2020

The fact that you need to use jira to validate if a user on bitbucket show how FLAWED bitbucket currently is.

0 votes
evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 28, 2016

Is it possible to get email addresses of user by using their username? 

No. Email addresses are considered somewhat personal and are not disclosed to other users.

Ramesh Kannan March 29, 2016

Are you saying even repository(private) admins also don't have permission to get emails of their users?

Like # people like this
evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 29, 2016

That is correct.

Now this approach is far from perfect, as you can look at the commit browser that resolves commits to Bitbucket accounts and then look at the email address in the raw commit object. However, we do not openly disclose user-to-email data).

Deleted user September 17, 2018

What if user need to reset the passwd and he's not sure what is the exact email address. or else resetting passwd of a common  checkout user . ho we can see where we get the mail. even site admin cant check the email address?

Ramesh Kannan October 23, 2018

Finally we moved to Gitlab. And it is offering full admin rights over all users

https://docs.gitlab.com/ee/api/users.html#for-admins

Like # people like this
Alexandr Marchenko March 20, 2019

Wondering how to achieve following: we have 40 people in our team and need to check whether all of them are using corporate email or not?

Or this one - we have email addresses for each team and wish to know how do they perform, but without knowing their bitbucket usernames it is not possible

Like # people like this
Steven Combs March 20, 2019

It is impossible with cloud, we have turned on SAML 2.0 in Jira to ensure that future users are signing up with Corporate mail but there is no way for us to tell with existing. We are also trying out bitbucket server to see if this could be a better option. 

Like Fricco likes this
Alexandr Marchenko March 20, 2019

Yes I understand that just wish to show few more use cases when this might be required. I do respect user privacy, but we are talking here for closed teams where we already do know everything about people in teams so hiding their emails seems like a pretty strange step. May be it is possible to show emails for private team members or something like this

Like # people like this
Stephen Estrada March 12, 2020

Totally agree @Alexandr Marchenko , when its private if you have access to the repo emails should be exposed. 

saint0192 May 7, 2020

Every time I think I've found the stupidest problem/omission with Atlassian products, I find another. As the admin on our account, I have personally invited users to our account to access our code for work. We have quite a few users, and at some point we were acquired by another company, so there are two email domains to our user's email addresses. As admin, I should have access to this info to migrate users to the newest iteration of email domain.

There should be no expectation of privacy protection over a user's email address who is accessing my PRIVATE account's repositories at my request. This is just flat out stupid.

Like # people like this
Pavel Smolianitsky July 12, 2020

Our team have about 340 private repositories, and all users have corporate e-mails, so they are not private, but as team administrator I can't get then via API? why? I can to understand rezone to not show on public repository e-mails of users to not team members, but inside same team or workspace why administrator can't get e-mail of his team member? what is purpose for this policy?

mient-jan October 22, 2020

There is no way to validate users on repositories. No one should use Bitbucket if they have security as a priority.

Eric Cooper October 29, 2020

This omission shows a blatant misunderstanding about how corporate technology works.  In order to use these endpoints, we need a reliable method to match BitBucket identities with corporate identities.  I know you want us to move to your cloud products. This is one of the many reasons we are moving in the opposite direction.  GitHub is just as bad in this regard.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events