0

I'm trying to download a file with the Azure Devops Rest API using Powershell's Invoke-RestMethod. It always seems to download from the main branch and ignores my branch specification

The urls I'm using are

invoke-restmethod -uri "https://dev.azure.com/company/xxx/_apis/git/repositories/xxx/items?path=%2Fpom.xml&commitOrBranch=main&api-version=6.0" -Method Get -ContentType "application/text" -Headers $headers

and

invoke-restmethod -uri "https://dev.azure.com/company/xxx/_apis/git/repositories/xxx/items?path=%2Fpom.xml&commitOrBranch=branchName&api-version=6.0" -Method Get -ContentType "application/text" -Headers $headers

How do I specify the branch? The documentation doesn't provide any details

Peter Kronenberg
  • 878
  • 10
  • 32
  • Does this answer your question? [How to download a file in a branch from a Git repo using Azure DevOps REST Api?](https://stackoverflow.com/questions/54228312/how-to-download-a-file-in-a-branch-from-a-git-repo-using-azure-devops-rest-api) – Yan Sklyarenko Jul 26 '21 at 15:18
  • This looks like an older version of the API which seems totally different. They seem to change the api frequently, and the documentation only includes a very brief description of the fields. – Peter Kronenberg Jul 27 '21 at 13:20

1 Answers1

2

You could try the below commandlet.

Just modified the below based on the question to download a pom.xml from the <BranchName>

invoke-restmethod -uri "https://dev.azure.com/company/xxx/_apis/git/repositories/xxx/items/pom.xml?versionType=Branch&version=<BranchName>" -Method Get -ContentType "application/text" -Headers $headers
Satya V
  • 3,811
  • 1
  • 6
  • 9
  • Yes, I had already figured this out based on additional research. I don't understand all the inconsistent documentation on this api, but this was the solution – Peter Kronenberg Aug 07 '21 at 13:28