Exact rest api is needed for fetching file list from a branch using Azure Devops Rest Api.
- 1What have you tried? What research have you done? What isn't working with your implementation?Daniel Mann– Daniel Mann2021-04-18 14:53:11 +00:00Commented Apr 18, 2021 at 14:53
- I am not getting exact rest api endpoints to fetch all file list from a branch using azure devops rest api. If you could help, it will be helpful for me.Harshita– Harshita2021-04-19 05:24:02 +00:00Commented Apr 19, 2021 at 5:24
Add a comment |
1 Answer
Fetch file list from Branch using Azure devops git rest api
You could use the REST API Items - List with query string parameter versionDescriptor.version and recursionLevel, documented as Version string identifier (name of tag/branch, SHA1 of commit).
So, we could use following URL:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?recursionLevel=Full&versionDescriptor.version=<YourBranchName>&api-version=5.0 Code sample:
$connectionToken="Your PAT" $base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)")) $Itemlisturl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?recursionLevel=Full&versionDescriptor.version=master&api-version=5.0" $ItemlistInfo = (Invoke-RestMethod -Uri $Itemlisturl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) $ItemlistName= $ItemlistInfo.value.path Write-Host "The list items of the branch master is = $($ItemlistName | ConvertTo-Json -Depth 100)" The test result:
1 Comment
Karanko
This help us a lot. its turns out you need to use a PAT to get recursion to work. if you are just testing the URLs in the browser recursionLevel seems to default to 'none' even if its set in the request
