BitBucket API for Users not returning repositories

I am using REST API to connect to BitBucket. I call into https://bitbucket.org/site/oauth2/access_token passing to it Consumer Key & Secret and it returns me access token. I then use that access token (as bearer) and pass it to my next API call https://api.bitbucket.org/1.0/users/avalidemail@mydomain.com

The returned JSON contains user name, etc but the repositories array is empty.

Where could I be going wrong?

My code is in Ruby:

 def GetUserAccess(userEmail)
        url = "https://bitbucket.org/site/oauth2/access_token"

        reqObj = RestClient::Resource.new url, strAuth_Consumer_Key, strAuth_Consumer_Secret
        responseData = reqObj.post "grant_type=client_credentials"
        puts responseData
        #Returns access_token, scopes, expires_in & refresh_token.
        #scopes = "pipeline:write webhook snippet:write wiki issue:write pullrequest:write repository:admin project:write team:write account:write"

        accessToken = 'Bearer ' + JSON.parse(responseData)["access_token"]
        headers = {Authorization: accessToken, accept: :json}

        url = "https://api.bitbucket.org/1.0/users/#{userEmail}"
        output = "BitBucket:".ljust(20)
        begin
            responseData = RestClient.get(url,headers)
            puts responseData
            #Returns User details which means user was found, but the repositories array is empty for all users.
            
            jsonObj = JSON.parse(responseData)
            output += "Has Access To Repos   "
            jsonObj["repositories"].each do |repo|
                output += repo["name"] + ",   "
            end
        rescue RestClient::NotFound, TypeError => e
            output += "No Access"
        end

        puts output
    end

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

262 views 3 8
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you