Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

API for Bitbucket

Deleted user September 6, 2019

I am looking for the REST API for Bitbucket to show the number of repositories. I spent a while researching, but still am at a loss. 

https://developer.atlassian.com/bitbucket/api/2/reference/resource/users

https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering#supp-endpoints

 

I also found this: 

https://docs.atlassian.com/bitbucket-server/rest/6.6.1/bitbucket-rest.html

 

If I input this: 

https://api.bitbucket.org/2.0/repositories

It provides information for a user and repository named "tweakmsg", so I suppose it is a stock response? 

When I try finding the repositories for my user on my Atlassian bitbucket account, it gives an error: 

https://api.bitbucket.org/2.0/repositories/users/{my user id}

{"type": "error", "error": {"message": "Repository users/{543f3bdf-9cc8-481b-8468-9021a69824d4} not found"}}

 

1 answer

0 votes
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 6, 2019

Hi @[deleted] 

From the answer by Blizzard in this, using

https://api.bitbucket.org/2.0/repositories?role=member

gives me all the repositories that I'm a member of.

Hope this helps

Deleted user September 6, 2019

Thanks!

Good news is I made progress and the first link is the weblink that is useful as a reference for my purposes: https://developer.atlassian.com/bitbucket/api/2/reference/resource/

Deleted user September 6, 2019

1.  Using my own user account as a test and trying to access repos:

https://api.bitbucket.org/2.0/repositories?role=member

The result is empty! I tried all the options (from contributor, owner, admin) Even tho I am listed as an owner to one repository.

Deleted user September 6, 2019

2. I was able to access initial information using the team UUID. 

Then am trying to use the teams/<uuid>/repositories, but based on the documentation it only returns empty: 

{“pagelen”: 10, “values”: [], “page”: 1, “size”: 0}

I supposedly have admin access to this team. 

Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 6, 2019

Hi @[deleted] 

How are you calling the API? cURL? Postman? Java? C#? Other?

You need to be authenticating with your Bitbucket username and an API token associated with that username - are you doing this? It may be useful to show the full call that you're sending off, with the token anonymised.

If you don't pass in authorisation, or the authorisation fails, then it will return all the public repositories, of which tweakmsg is the first one.

Deleted user September 6, 2019

Hi, 

 

Thanks for the reply! 

1.
Using API (Browser - Chrome). I have also used curl in the past.

I have noticed that when I go to: 

https://api.bitbucket.org/2.0/users/<uuid>/members

to check my access:

{"type": "error", "error": {"message": "Forbidden"}}

This is the output. 

 

2. https://api.bitbucket.org/2.0/teams/<team uuid>/permissions/repositories

Shows a login prompt. I enter my username and pw. I cannot log in with my account (loops to ask for login again). Once again, I supposedly have admin access to the team, but also, it seems I am unable to log in to view this. 

Does there need to be a separate permission granted for users to use api.bitbucket.org?

Deleted user September 6, 2019

Ok, I'll authenticate using curl, and let you know! :) 

Deleted user September 10, 2019

Hi, I have access to a token which is 32 characters long. Is the same length as an expected API token to curl? Thanks!

Deleted user September 10, 2019

After trying a few things, creating the App Password works for me. https://confluence.atlassian.com/bitbucket/app-passwords-828781300.html?_ga=2.120538568.1500375385.1568137015-2069897606.1563555800

Thanks, I was able to successfully find: 

https://api.bitbucket.org/2.0/teams/<team uuid>/permissions/repositories

I tried looking at the repositories to get the repo count: 

https://api.bitbucket.org/2.0/teams/<team uuid>/repositories

{"pagelen": 10, "values": [], "page": 1, "size": 0}

 which shouldn't be the case. Appreciate your help!

Deleted user September 10, 2019

https://developer.atlassian.com/bitbucket/api/2/reference/resource/teams/%7Busername%7D/repositories <-- Even after reading this, I would assume we can view the repositories. But the default value is an 'error' even in the documentation. Can someone please confirm that this endpoint is in use? Thanks!

Deleted user September 10, 2019

Ok, I found the answer. Both the project and repository need to be set to public in order to view the https://developer.atlassian.com/bitbucket/api/2/reference/resource/teams/%7Busername%7D/repositories.

This API also redirects to https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D. 

Deleted user September 10, 2019

^ The above means that `All repositories owned by a user/team. This includes private repositories, but filtered down to the ones that the calling user has access to.` is deprecated...

Any help with viewing repositories without having to make access public? 

Deleted user September 10, 2019

@Warren Hi! Wondering if I can view repositories without making access public. Since it looks like private repositories cannot be viewed as shown the deprecated link above. I am looking for a way to count the number of repositories and can filter the repo based on number of links. Thanks!

Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2019

Hi @[deleted] 

I was struggling to follow all the info that you've given here, but I can say that all our repositories are Private and I can view them via the API, so you don't need to make them all public to see them. The user whose details are used for the API call will need access rights to view those repositories.

You may want to post your question on the Developer Community site as well, to increase your chances of getting help

Deleted user September 11, 2019

Hi Warren, 

Thank you for the reply. Unfortunately, even though I am in the administrator group, I cannot see the projects nor repositories. 

Can you paste to me the API that you are using to be able to see the repositories? I tried using users which have admin access and also the team uuid. 

It would be ideal to be able to view the API without having to use additional credentials

Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2019

Hi @[deleted] 

Reading back what you've written, I think the issue may be that you are using the browser, which isn't allowing you to authenticate. I would recommend that you try doing this via Postman (either online or download the free app) to know that your authentication is working. You can see from the screenshot below that I'm using Basic Auth and my username and API token to successfully get data returned.

 

Once you get to this point using Postman and know that it is working, you can then try some other route.

Screenshot_2.jpg

Deleted user September 11, 2019

Thanks so much!! I'll try that! :) 

Deleted user September 11, 2019

Ok, I've been able to get my results using Postman. :)  I was able to authenticate using the browser as well. This is for my own user. 

 

When I use the team uuid, I cannot view the repos. Any help with this, as this is my main goal :) 

Deleted user September 11, 2019

Hi @Warren 

Definitely the following link works for others, but not for me: 

https://community.atlassian.com/t5/Bitbucket-questions/How-to-get-all-private-repos-owned-by-team/qaq-p/763371

They are using: 

https://api.bitbucket.org/2.0/repositories/{TeamName} 

 

Deleted user September 11, 2019
Deleted user September 11, 2019

@Warren Thank you so much!
It worked!! Using postman, and adding the parameter: `scopes=repository` worked, as that was missing in the API call!!

Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2019

Hi @[deleted] 

I'm glad that you're finally able to get the results that you need. I have never used scopes=repository so I guess that mine were correctly set by default.

Deleted user September 12, 2019

Thank you so much for all your help, Warren! Yes, I think you had the settings by default. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events