How can I set the page size of branches on V2.0?

ben-codefresh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 10, 2016

This question is in reference to Atlassian Documentation: Use the Bitbucket Cloud REST APIs

I need to get a list of branches from my repo. I try this:
https://bitbucket.org/api/2.0/repositories/<repo_name>/<slug>/refs/branches and I get an object:

{

"pagelen": 10,
"size": 12,
"values": ...

"page":1

"next": <link>

}

I want to get more (or possibly more) branches. I tried:
 https://bitbucket.org/api/2.0/repositories/<repo_name>/<slug>/refs/branches?limit=1000 but got nothing different. 

  1. Is there a way to get all the branches?
  2. Is there a way to get just the branch names?

 

Ben

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
abhin-atl
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.
August 10, 2016

Hi Ben,

You can increase the page length of the returned response by using the pagelen query parameter. But most Bitbucket APIs have a maximum permissible pagelength (usually 100). So in the case of the branches API, you can increase the page length all the way to 100, but no more. You'll still have to page through the branches.

Luis Matos August 1, 2017

Is there a way to see page 2 but keep the pagelen at 100?  I have attempted the following, but to no avail:

 

https://api.bitbucket.org/2.0/repositories/teamname?pagelen=100&page=2

 

https://api.bitbucket.org/2.0/repositories/teamname?page=2&pagelen=100

Noah Sutherland
Contributor
January 22, 2019

Luis, this appears to be fixed. I just tried it and it worked for me.

Luis Matos February 1, 2019

Noah helped me understand that urls with multiple parameters need to be in quotes to be recognized by the bitbucket API 2.0.

Example:

curl "https://api.bitbucket.org/2.0/repositories/{teamname}?pagelen=100&page=2"

Noah Sutherland
Contributor
February 1, 2019

Yeah, I don't actually remember my thought processes on why I put the quotes on. But I think that & is a reserved character in bash so probably had to do it for that.

Like # people like this
0 votes
Ben 1984
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 10, 2016

Hi @Abhin Chhabra,

Thanks for the reply. I tried before with pagelen=1000 and got just 10. Now that you told me that the limit is 100 I tried pagelen=100 and it worked. Thanks a lot.

Do you know if there's a way to get just the names without limit? 
I need to show just a list of branches, and getting all this useless data is redundant.

 

 

abhin-atl
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.
August 11, 2016

There is an undocumented way (it's undocumented because it's not finished). We accept an undocumented query parameter called fields that can be used for excluding fields (or even for including fields that don't usually get included).

For example, one could do:

$ curl https://api.bitbucket.org/2.0/repositories/pypy/pypy/refs/branches\?pagelen\=1\&amp;fields\="-values.heads,-values.links,-values.repository,-values.target" | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   262  100   262    0     0    344      0 --:--:-- --:--:-- --:--:--   344
{
  "pagelen": 1,
  "size": 1449,
  "values": [
    {
      "type": "named_branch",
      "name": "0.6"
    }
  ],
  "page": 1,
  "next": "https://api.bitbucket.org/2.0/repositories/pypy/pypy/refs/branches?pagelen=1&amp;page=2&amp;fields=-values.heads%2C-values.links%2C-values.repository%2C-values.target"
}

You can exclude even more fields from the list. I hope this helps.

TAGS
AUG Leaders

Atlassian Community Events