Search code examples
tfsazure-devops-rest-apiazure-devops-server-2019

Get List of Collection REST API - Azure DevOps Server (TFS)


I am trying to get list of collection in from Azure DevOps Server. There is no API available to fetch the list of collections.

[tfs url]/_apis/projectCollections?$top=1000

I tried above API (PAT authorization)


Solution

  • To get all the collections which your account has access to, you can try the steps below.

    1. Create a PAT for all accessible organizations

      enter image description here

    2. Run the following PowerShell scripts.

    $token = "{PAT}"
    $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
    $url="{Server URL}/_apis/projectCollections?%24top=1000?api-version=7.1-preview.2"
    $head = @{ Authorization =" Basic $token" }
    $result = Invoke-RestMethod -Uri $url -Method GET -Headers $head
    $result| ConvertTo-Json
    
    • PAT: You create in step 1.

    • Server URL: Copy the part of your collection URL before the collection name. Taking the following screenshot as an example, it should be http://wi***

      enter image description here

    • Result: enter image description here