2

Exact rest api is needed for fetching file list from a branch using Azure Devops Rest Api.

2
  • 1
    What have you tried? What research have you done? What isn't working with your implementation? Commented 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. Commented Apr 19, 2021 at 5:24

1 Answer 1

2

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:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.