Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get user email address using BitBucket API?

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

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

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

Like # people like this
Like M Saqib Aziz likes this

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

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 Mar 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.

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 Mar 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 Sep 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?

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

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

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

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

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

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

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?

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

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
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

117 views 2 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you