您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Resources - Resources

Queries the resources managed by Azure Resource Manager for all subscriptions specified in the request.

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01

URI Parameters

Name In Required Type Description
api-version
query True
  • string

API version.

Request Body

Name Required Type Description
facets

An array of facet requests to be computed against the query result.

options

The query evaluation options

query True
  • string

The resources query.

subscriptions True
  • string[]

Azure subscriptions against which to execute the query.

Responses

Name Type Description
200 OK

Result of the query operation

Other Status Codes

An error occurred while processing the request. See the error.code parameter to identify the specific error.

Security

azure_auth

Azure Active Directory OAuth2 Flow

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
user_impersonation impersonate your user account

Examples

Access a properties field
Access a properties field through alias
Basic query
Complex query
Filter resources
First page query
Next page query
Query options
Query with a facet request
Random page query
Summarize resources by location

Access a properties field

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"
}

Sample Response

{
  "totalRecords": 2,
  "count": 2,
  "resultTruncated": "false",
  "data": {
    "columns": [
      {
        "name": "properties_storageProfile_osDisk_osType",
        "type": "string"
      },
      {
        "name": "count_",
        "type": "integer"
      }
    ],
    "rows": [
      [
        "Linux",
        7
      ],
      [
        "Windows",
        23
      ]
    ]
  }
}

Access a properties field through alias

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "where type =~ 'Microsoft.Web/serverFarms' | extend skuName = tostring(aliases['Microsoft.Web/serverfarms/sku.name']) | summarize count() by skuName"
}

Sample Response

{
  "totalRecords": 3,
  "count": 3,
  "resultTruncated": "false",
  "data": {
    "columns": [
      {
        "name": "skuName",
        "type": "string"
      },
      {
        "name": "count_",
        "type": "integer"
      }
    ],
    "rows": [
      [
        "S2",
        1
      ],
      [
        "Y1",
        3
      ],
      [
        "S1",
        1
      ]
    ]
  }
}

Basic query

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "project id, name, type, location, tags | limit 3"
}

Sample Response

{
  "totalRecords": 3,
  "count": 3,
  "resultTruncated": "false",
  "data": {
    "columns": [
      {
        "name": "id",
        "type": "string"
      },
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "type",
        "type": "string"
      },
      {
        "name": "location",
        "type": "string"
      },
      {
        "name": "tags",
        "type": "object"
      }
    ],
    "rows": [
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
        "myNetworkInterface",
        "microsoft.network/networkinterfaces",
        "centralus",
        {
          "tag1": "Value1"
        }
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
        "myVnet",
        "microsoft.network/virtualnetworks",
        "westus",
        {}
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
        "myPublicIp",
        "microsoft.network/publicipaddresses",
        "westus",
        {}
      ]
    ]
  }
}

Complex query

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_"
}

Sample Response

{
  "totalRecords": 3,
  "count": 3,
  "resultTruncated": "false",
  "data": {
    "columns": [
      {
        "name": "location",
        "type": "string"
      },
      {
        "name": "count_",
        "type": "integer"
      }
    ],
    "rows": [
      [
        "centralus",
        11
      ],
      [
        "eastus",
        11
      ],
      [
        "southcentralus",
        3
      ]
    ]
  }
}

Filter resources

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | limit 3"
}

Sample Response

{
  "totalRecords": 3,
  "count": 3,
  "resultTruncated": "false",
  "data": {
    "columns": [
      {
        "name": "id",
        "type": "string"
      },
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "type",
        "type": "string"
      },
      {
        "name": "location",
        "type": "string"
      }
    ],
    "rows": [
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/virtualMachines/myVm1",
        "myVm1",
        "microsoft.compute/virtualmachines",
        "centralus"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Compute/virtualMachines/myVirtualMachine",
        "myVirtualMachine",
        "microsoft.compute/virtualmachines",
        "eastus"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG3/providers/Microsoft.Compute/virtualMachines/testVm",
        "testVm",
        "microsoft.compute/virtualmachines",
        "eastus"
      ]
    ]
  }
}

First page query

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "where name contains 'test' | project id, name, type, location",
  "options": {
    "$top": 3,
    "$skip": 0
  }
}

Sample Response

{
  "totalRecords": 386,
  "count": 3,
  "resultTruncated": "false",
  "$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ==",
  "data": {
    "columns": [
      {
        "name": "id",
        "type": "string"
      },
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "type",
        "type": "string"
      },
      {
        "name": "location",
        "type": "string"
      }
    ],
    "rows": [
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
        "yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
        "microsoft.compute/disks",
        "eastus"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA",
        "TestAA",
        "microsoft.automation/automationaccounts",
        "westcentralus"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA/runbooks/TestRB",
        "TestRB",
        "microsoft.automation/automationaccounts/runbooks",
        "westcentralus"
      ]
    ]
  }
}

Next page query

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "where name contains 'test' | project id, name, type, location",
  "options": {
    "$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ=="
  }
}

Sample Response

{
  "totalRecords": 386,
  "count": 3,
  "resultTruncated": "false",
  "$skipToken": "eyAibm8yIjogImx1Y2syIiwgImJ1dDIiOiAibmljZTIiLCAidHJ5MiI6ICIhIiB9",
  "data": {
    "columns": [
      {
        "name": "id",
        "type": "string"
      },
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "type",
        "type": "string"
      },
      {
        "name": "location",
        "type": "string"
      }
    ],
    "rows": [
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/second_OsDisk_dddddbcb625a457bb69fe2abf5975820",
        "second_OsDisk_dddddbcb625a457bb69fe2abf5975820",
        "microsoft.compute/disks",
        "eastus"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/AATest",
        "AATest",
        "microsoft.automation/automationaccounts",
        "westcentralus"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA/runbooks/RBTest",
        "RBTest",
        "microsoft.automation/automationaccounts/runbooks",
        "westcentralus"
      ]
    ]
  }
}

Query options

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "where name contains 'test' | project id, name, type, location",
  "options": {
    "$top": 3,
    "$skip": 10
  }
}

Sample Response

{
  "totalRecords": 386,
  "count": 3,
  "resultTruncated": "false",
  "$skipToken": "eyAibm8yIjogImx1Y2syIiwgImJ1dDIiOiAibmljZTIiLCAidHJ5MiI6ICIhIiB9",
  "data": {
    "columns": [
      {
        "name": "id",
        "type": "string"
      },
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "type",
        "type": "string"
      },
      {
        "name": "location",
        "type": "string"
      }
    ],
    "rows": [
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG4/providers/Microsoft.Compute/disks/yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
        "yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
        "microsoft.compute/disks",
        "eastus"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG5/providers/Microsoft.Automation/automationAccounts/TestAA",
        "TestAA",
        "microsoft.automation/automationaccounts",
        "westcentralus"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG5/providers/Microsoft.Automation/automationAccounts/TestAA/runbooks/TestRB",
        "TestRB",
        "microsoft.automation/automationaccounts/runbooks",
        "westcentralus"
      ]
    ]
  }
}

Query with a facet request

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "where type =~ 'Microsoft.Compute/virtualMachines' | project id, name, location, resourceGroup, properties.storageProfile.osDisk.osType | limit 5",
  "facets": [
    {
      "expression": "location",
      "options": {
        "sortOrder": "desc",
        "$top": 3
      }
    },
    {
      "expression": "properties.storageProfile.osDisk.osType",
      "options": {
        "sortOrder": "desc",
        "$top": 3
      }
    },
    {
      "expression": "nonExistingColumn",
      "options": {
        "sortOrder": "desc",
        "$top": 3
      }
    },
    {
      "expression": "resourceGroup",
      "options": {
        "sortBy": "tolower(resourceGroup)",
        "sortOrder": "asc",
        "$top": 3
      }
    },
    {
      "expression": "resourceGroup",
      "options": {
        "filter": "resourceGroup contains 'test'",
        "$top": 3
      }
    }
  ]
}

Sample Response

{
  "totalRecords": 5,
  "count": 5,
  "resultTruncated": "false",
  "data": {
    "columns": [
      {
        "name": "id",
        "type": "string"
      },
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "location",
        "type": "string"
      },
      {
        "name": "resourceGroup",
        "type": "string"
      },
      {
        "name": "properties_storageProfile_osDisk_osType",
        "type": "object"
      }
    ],
    "rows": [
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/B-TEST-RG/providers/Microsoft.Compute/virtualMachines/myTestVm",
        "myTestVm",
        "eastus",
        "B-TEST-RG",
        "Windows"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/c-rg/providers/Microsoft.Compute/virtualMachines/myTestAccountVm",
        "myTestAccountVm",
        "westcentralus",
        "c-rg",
        "Windows"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/I-RG/providers/Microsoft.Compute/virtualMachines/yetanothertest",
        "yetanothertest",
        "eastus",
        "I-RG",
        "Linux"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/x-test-rg/providers/Microsoft.Compute/virtualMachines/drafttest1bux4cv7a7q3aw",
        "drafttest1bux4cv7a7q3aw",
        "southcentralus",
        "x-test-rg",
        "Linux"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/y-rg/providers/Microsoft.Compute/virtualMachines/testvmntp25370",
        "testvmntp25370",
        "eastus",
        "y-rg",
        "Windows"
      ]
    ]
  },
  "facets": [
    {
      "expression": "location",
      "resultType": "FacetResult",
      "totalRecords": 3,
      "count": 3,
      "data": {
        "columns": [
          {
            "name": "location",
            "type": "string"
          },
          {
            "name": "count",
            "type": "integer"
          }
        ],
        "rows": [
          [
            "eastus",
            3
          ],
          [
            "southcentralus",
            1
          ],
          [
            "westcentralus",
            1
          ]
        ]
      }
    },
    {
      "expression": "properties.storageProfile.osDisk.osType",
      "resultType": "FacetResult",
      "totalRecords": 2,
      "count": 2,
      "data": {
        "columns": [
          {
            "name": "properties_storageProfile_osDisk_osType",
            "type": "string"
          },
          {
            "name": "count",
            "type": "integer"
          }
        ],
        "rows": [
          [
            "Linux",
            2
          ],
          [
            "Windows",
            3
          ]
        ]
      }
    },
    {
      "expression": "nonExistingColumn",
      "resultType": "FacetError",
      "errors": [
        {
          "code": "NoValidColumns",
          "message": "No valid columns in facet expression."
        },
        {
          "code": "InvalidColumnNames",
          "message": "Invalid column names: [nonExistingColumn]."
        }
      ]
    },
    {
      "expression": "resourceGroup",
      "resultType": "FacetResult",
      "totalRecords": 5,
      "count": 3,
      "data": {
        "columns": [
          {
            "name": "resourceGroup",
            "type": "string"
          },
          {
            "name": "count",
            "type": "integer"
          }
        ],
        "rows": [
          [
            "B-TEST-RG",
            1
          ],
          [
            "c-rg",
            1
          ],
          [
            "I-RG",
            1
          ]
        ]
      }
    },
    {
      "expression": "resourceGroup",
      "resultType": "FacetResult",
      "totalRecords": 2,
      "count": 2,
      "data": {
        "columns": [
          {
            "name": "resourceGroup",
            "type": "string"
          },
          {
            "name": "count",
            "type": "integer"
          }
        ],
        "rows": [
          [
            "B-TEST-RG",
            1
          ],
          [
            "x-test-rg",
            1
          ]
        ]
      }
    }
  ]
}

Random page query

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "where name contains 'test' | project id, name, type, location",
  "options": {
    "$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ==",
    "$top": 2,
    "$skip": 10
  }
}

Sample Response

{
  "totalRecords": 386,
  "count": 2,
  "resultTruncated": "false",
  "$skipToken": "eyAibm8yIjogImx1Y2syIiwgImJ1dDIiOiAibmljZTIiLCAidHJ5MiI6ICIhIiB9",
  "data": {
    "columns": [
      {
        "name": "id",
        "type": "string"
      },
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "type",
        "type": "string"
      },
      {
        "name": "location",
        "type": "string"
      }
    ],
    "rows": [
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/third_OsDisk_dddddbcb625a457bb69fe2abf5975820",
        "third_OsDisk_dddddbcb625a457bb69fe2abf5975820",
        "microsoft.compute/disks",
        "eastus"
      ],
      [
        "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/CCTest",
        "CCTest",
        "microsoft.automation/automationaccounts",
        "westcentralus"
      ]
    ]
  }
}

Summarize resources by location

Sample Request

POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01
{
  "subscriptions": [
    "cfbbd179-59d2-4052-aa06-9270a38aa9d6"
  ],
  "query": "project id, name, type, location | summarize by location"
}

Sample Response

{
  "totalRecords": 3,
  "count": 3,
  "resultTruncated": "false",
  "data": {
    "columns": [
      {
        "name": "location",
        "type": "string"
      }
    ],
    "rows": [
      [
        "centralus"
      ],
      [
        "eastus"
      ],
      [
        "westus"
      ]
    ]
  }
}

Definitions

Column

Query result column descriptor.

ColumnDataType

Data type of a column in a table.

Error

Error info.

ErrorDetails

Error details.

ErrorResponse

Error response.

FacetError

A facet whose execution resulted in an error.

FacetRequest

A request to compute additional statistics (facets) over the query results.

FacetRequestOptions

The options for facet evaluation

FacetResult

Successfully executed facet containing additional statistics on the response of a query.

FacetSortOrder

The sorting order by the selected column (count by default).

QueryRequest

Describes a query to be executed.

QueryRequestOptions

The options for query evaluation

QueryResponse

Query result.

ResultTruncated

Indicates whether the query results are truncated.

Table

Query output in tabular format.

Column

Query result column descriptor.

Name Type Description
name
  • string

Column name.

type

Column data type.

ColumnDataType

Data type of a column in a table.

Name Type Description
boolean
  • string
integer
  • string
number
  • string
object
  • string
string
  • string

Error

Error info.

Name Type Description
code
  • string

Error code identifying the specific error.

details

Error details

message
  • string

A human readable error message.

ErrorDetails

Error details.

Name Type Description
code
  • string

Error code identifying the specific error.

message
  • string

A human readable error message.

ErrorResponse

Error response.

Name Type Description
error

Error info.
Error information.

FacetError

A facet whose execution resulted in an error.

Name Type Description
errors

An array containing detected facet errors with details.

expression
  • string

Facet expression, same as in the corresponding facet request.

resultType string:

Result type

FacetRequest

A request to compute additional statistics (facets) over the query results.

Name Type Description
expression
  • string

The column or list of columns to summarize by

options

The options for facet evaluation

FacetRequestOptions

The options for facet evaluation

Name Type Description
$top
  • integer

The maximum number of facet rows that should be returned.

filter
  • string

Specifies the filter condition for the 'where' clause which will be run on main query's result, just before the actual faceting.

sortBy
  • string

The column name or query expression to sort on. Defaults to count if not present.

sortOrder

The sorting order by the selected column (count by default).

FacetResult

Successfully executed facet containing additional statistics on the response of a query.

Name Type Description
count
  • integer

Number of records returned in the facet response.

data

A table containing the desired facets. Only present if the facet is valid.

expression
  • string

Facet expression, same as in the corresponding facet request.

resultType string:

Result type

totalRecords
  • integer

Number of total records in the facet results.

FacetSortOrder

The sorting order by the selected column (count by default).

Name Type Description
asc
  • string
desc
  • string

QueryRequest

Describes a query to be executed.

Name Type Description
facets

An array of facet requests to be computed against the query result.

options

The query evaluation options

query
  • string

The resources query.

subscriptions
  • string[]

Azure subscriptions against which to execute the query.

QueryRequestOptions

The options for query evaluation

Name Type Description
$skip
  • integer

The number of rows to skip from the beginning of the results. Overrides the next page offset when $skipToken property is present.

$skipToken
  • string

Continuation token for pagination, capturing the next page size and offset, as well as the context of the query.

$top
  • integer

The maximum number of rows that the query should return. Overrides the page size when $skipToken property is present.

QueryResponse

Query result.

Name Type Description
$skipToken
  • string

When present, the value can be passed to a subsequent query call (together with the same query and subscriptions used in the current request) to retrieve the next page of data.

count
  • integer

Number of records returned in the current response. In the case of paging, this is the number of records in the current page.

data

Query output in tabular format.

facets Facet[]:

Query facets.

resultTruncated

Indicates whether the query results are truncated.

totalRecords
  • integer

Number of total records matching the query.

ResultTruncated

Indicates whether the query results are truncated.

Name Type Description
false
  • string
true
  • string

Table

Query output in tabular format.

Name Type Description
columns

Query result column descriptors.

rows
  • array[]

Query result rows.