How can I get the list of forks via Azure DevOps REST API related to a particular repo?
I was checking the doc on this:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryNameOrId}/forks/{collectionId}?api-version=5.1-preview.1
However, there are no examples provided. In particular, I cannot figure out what {collectionid}
is and where I can get it.
I contrast to this, for example, I have no issues with listing repos following the below GET method:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=5.1
The PowerShell script:
$AzureDevOpsPAT = "<PAT>"
$OrganizationName = "<OrganizationName>"
$Project = "<ProjectName>"
$UriOrga = "https://dev.azure.com/$($OrganizationName)/"
$UriProj = $UriOrga + "$($Project)/"
$RepoName = "<RepoName>"
$uriRepo = $UriProj + "_apis/git/repositories/$RepoName"
$uriListRepos = $uriRepo + "?api-version=5.1"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)"))}
$Forks = (Invoke-RestMethod -Uri $uriListRepos -Method get -Headers $AzureDevOpsAuthenicationHeader) | Write-Host
But the "Repositories - List" formula looks a bit differenly from "Forks - List".
Your help with listing Forks would be very appreciated.
collectionId
is actually the (internal) id of your organization and that you can get that by POST:ing:https://dev.azure.com/{{organization}}/_apis/Contribution/HierarchyQuery?api-version=5.0-preview.1
, with this request body: { "contributionIds": ["ms.vss-features.my-organizations-data-provider"], "dataProviderContext": { "properties":{} } } – Jonas Rembratt