Harshita
Harshita

Reputation: 147

Fetch file list from Branch using Azure devops git rest api

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

Upvotes: 2

Views: 2034

Answers (1)

Leo Liu
Leo Liu

Reputation: 76670

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

Upvotes: 2

Related Questions