Search code examples
bitbucketbitbucket-api

Bitbucket REST Api: How can I order all branches by date desc with rest api call?


I need to get the name of the latest branch. So, I list branches but the order of the list is not by created date desc.

And the below api call doesn't work. Its response is like that "message": "Invalid field name: updated_on"

https://api.bitbucket.org/2.0/repositories/{user_name}/{repo_name}/refs/branches?sort=-updated_on

Thanks & Best Regards


Solution

  • I've found the answer. All branches have target field and the target has date field. So, in order to sort the branches by date you need to point target's date by "target.date"

    Like below:

    https://api.bitbucket.org/2.0/repositories/{user_name}/{repo_name}/refs/branches?sort=-target.date