How can I get the full list of repositories with REST API

nellinux February 17, 2020

I can get the list of my repositories or the repositories of the groups I belong to, with:

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

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

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

But, how can I get the full list of the repositories I have access permission?

Thank you.

  Nello

2 answers

2 accepted

1 vote
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 18, 2020

Hello @nellinux,

Welcome to the Community!

Here's the endpoint that returns exactly what you're after:

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

Here's the relevant API documentation page.

Hope this helps. Let me know if you have any questions.

Cheers,
Daniil

0 votes
Answer accepted
ruben.labruyere February 18, 2020

While I admit Atlassian would do great on having an API call that just simply generates a list no matter the size but nooo they had to make it difficult. :')

Your best bet is to use the API call "/repositories/{your_team}/pagelen=25". This will return a paginated result. Good thing about it, is that the response comes with a property "Next". Which holds the url of the API call to get the next page of results.

So the steps you need to take are:

1) POST /repositories/{your_team}/pagelen=25

2) Parse the JSON response. This looks like:

{

"page": 1,

"pagelen": 25,

"next": "/repositories/{your_team}/pagelen=25&startsAt=25"

"previous": "...",

"values":  []

}

3) Send the POST request with as url the value of the above "next" property

4) Repeat steps until the values.length < pagelen

nellinux February 18, 2020

Thank you :-)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events