Azure REST API Get Branches returning 0 branches

Viewed 1965

I am trying to get all branches for a project with

https://dev.azure.com/$organization/$project/_apis/tfvc/branches?&api- 
version=5.0

I use the credentials, organization, and project variables in other queries that are working. The request format is based off the example here

https://docs.microsoft.com/en-us/rest/api/azure/devops/tfvc/branches/get?view=azure-devops-rest-5.0

The response I am getting is

count value
----- -----
    0 {} 

when there are many branches in the repository.

Should I be specifying the repository somewhere? Or what else? Thanks!

1 Answers

First you need to confirm which type of repository you need to use rest API to get branch from, git or tfvc.

If you want to get branches from a tfvc repo, then use the rest api as you refer to in your case.

But, you need to be aware that if the count you want to return is not 0, you should ensure that there are branches in your tfvc repo, not just folders and files.

To convert the folder in tfvc repo to branch, you can convert it in vs source control explorer. For details, please refer to this docs.

enter image description here

If you want to get branches from a git repo, you need to use the rest API as follows.

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=5.0

enter image description here

Related