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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

181 views 20 8
Join discussion

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