Get all organizations in Azure DevOps using REST API

后端 未结 5 1601
谎友^
谎友^ 2020-12-19 03:39

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.co         


        
5条回答
  •  -上瘾入骨i
    2020-12-19 04:12

    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.

提交回复
热议问题