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

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 can I set the page size of branches on V2.0?

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

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, this appears to be fixed. I just tried it and it worked for me.

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"

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

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.

 

 

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
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

78 views 1 6
Read article

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