Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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 use bitbucket cloud APIs ?

Bitbucket cloud APIs have a good documentation, but I could not find a comprehensive examples showing how to make authenticated calls to those APIs.

My requirement is very simple.  As a bitbucket cloud admin for a given workspace, I would like to get a list of all the repos the workspace has.

I would like to be able to do this from my python backend (a simple script & nothing else). There is no user interaction involved in this case.  Now having gone through the documentation & a bunch of online resources, it appears that there are a few ways to get authentication tokens, which is (obviously) the first step to be able to call any other APIs.

Here are a few things I'm struggling with & would really appreciate any inputs around the same : (PS: pointing me to the right resources would also be great help. Don't necessarily need direct spoon fed answers :) )

  1. What's the difference between the different tokens? On Bitbucket cloud I can see App Tokens & Oauth Consumers. Which one is the one to be used in my case above? And with each, what should be the respective header value?

  2. What's the endpoint to which the call needs to be made? For example to get a list of the all repos in the given workspace, for which I am an admin, would it be https://api.bitbucket.org/2.0/repositories/<my_workspace_name_here> or would it be https://bitbucket.org/<my_workspace_name_here>/2.0/repositories/ or would it be something else? 

  3. There is this official python lib from Atlassian https://atlassian-python-api.readthedocs.io/index.html which does seem to talk about how to get the authentication done for Bitbucket cloud using the app password, something like using the below:

    bitbucket_app_pw = Cloud(
        url='https://api.bitbucket.org/',
        username=bitbucket_username,
        password=bitbucket_app_password,
        cloud=True)

and then the corresponding API call to list the repos seems to be 

bitbucket.project_list()

but the bitbucket Cloud object (in this case bitbucket_app_pw), obtained from the former snippet above, does not seem to have the project_list method at all. Am I missing something here?

1 answer

About the part of your question concerning project_list(): you need to get a workspace object in order to get a list of projects.

So you could do something like this:

bitbucket.workspaces.get(<my_workspace_name_here>).projects.each()

and you would get a generator for project objects.

This has been working for me using the app-password authentication you mentioned in #3.

 

About #2, the endpoint you should be using is:

https://api.bitbucket.org/2.0/repositories/<my_workspace_name_here> 

curl -u username:app_password https://api.bitbucket.org/2.0/repositories/<my_workspace_name_here>

 

I don't know about #1.

Suggest an answer

Log in or Sign up to answer
TAGS

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