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 Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

638 views 0 4
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot