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.
Ben
Community moderators have prevented the ability to post new answers.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Luis, this appears to be fixed. I just tried it and it worked for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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\&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&page=2&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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.