Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all organizations in Azure DevOps using REST API

I am trying to retrieve all the organizations in my account but in the documentation an organization is always required in the API call.

https://dev.azure.com/{organization}/_apis/...
like image 208
Kamil Avatar asked Feb 19 '19 09:02

Kamil


People also ask

Does Azure DevOps have a REST API?

Welcome to the Azure DevOps Services/Azure DevOps Server REST API Reference. Representational State Transfer (REST) APIs are service endpoints that support sets of HTTP operations (methods), which provide create, retrieve, update, or delete access to the service's resources.


1 Answers

you can do it simply by making a call to get all the account you are member/ owner of. However for that you need your id, which can be easily fetched by making get profile call. Here are steps below:

  1. Make a VSTS API call to get profile details using Bearer token or PAT

https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=5.1

This will return you, your Id:

{
    "displayName": "xxxx",
    "publicAlias": "xxx",
    "emailAddress": "xxx",
    "coreRevision": xxx,
    "timeStamp": "2019-06-17T09:29:11.1917804+00:00",
    "id": "{{We need this}}",
    "revision": 298459751
}
  1. Next, make a call to get all the accounts you are member of or owner of:

https://app.vssps.visualstudio.com/_apis/accounts?api-version=5.1&memberId={{Your Id}}

Response:

{
    "count": 1,
    "value": [
        {
            "accountId": "xxx",
            "accountUri": "xxx",
            "accountName": "xxx",
            "properties": {}
        }
    ]
}

It will return list of accounts you are associated with.

like image 130
Nikheel Avatar answered Oct 06 '22 13:10

Nikheel