Get all organizations in Azure DevOps using REST A

2019-08-06 12:21发布

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

2条回答
时光不老,我们不散
2楼-- · 2019-08-06 12:59

A REST API request/response pair can be separated into five components:

The request URI, in the following form:

VERB https://{instance}[/{team-project}]/_apis[/{area}]/{resource}?api-version={version}

instance: The Azure DevOps Services organization or TFS server you're sending the request to.

They are structured as follows: Azure DevOps Services: dev.azure.com/{organization}

The REST API's are organization specific. This is not documented at present. You could submit a feature request here: https://developercommunity.visualstudio.com/spaces/21/index.html

Our PM and product team will kindly review your suggestion. Sorry for any inconvenience.

As a workaround, you could use the API which captured from network traffic just as Matt mentioned.

查看更多
霸刀☆藐视天下
3楼-- · 2019-08-06 13:11

If you load the current landing page, it displays all your organizations tied to your account. I assumed it had to get that information some way. I captured the network traffic and I believe you could get to the data you want using a system API call. However, it might change or might become unsupported without notice, so use at your own discretion.

You can get the information you want using this API:

Post https://dev.azure.com/{organization1}/_apis/Contribution/HierarchyQuery?api-version=5.0-preview.1

Body:

{
    "contributionIds": ["ms.vss-features.my-organizations-data-provider"],
    "dataProviderContext":
        {
            "properties":{}
        }
}

Response:

{
    "dataProviderSharedData": {},
    "dataProviders": {
        "ms.vss-web.component-data": {},
        "ms.vss-web.shared-data": null,
        "ms.vss-features.my-organizations-data-provider": {
            "organizations": [
                {
                    "id": "{redacted id}",
                    "name": "{organization1}",
                    "url": "https://{organization1}.visualstudio.com/"
                },
                {
                    "id": "{redacted id}",
                    "name": "{organization2}",
                    "url": "https://dev.azure.com/{organization2}/"
                }
            ],
            "createNewOrgUrl": "https://app.vsaex.visualstudio.com/go/signup?account=true"
        }
    } }
查看更多
登录 后发表回答