Esegue una query sulle risorse gestite da Azure Resource Manager per individuare gli ambiti specificati nella richiesta.
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
Parametri dell'URI
| Nome |
In |
Necessario |
Tipo |
Descrizione |
|
api-version
|
query |
True
|
string
minLength: 1
|
Versione dell'API da usare per questa operazione.
|
Corpo della richiesta
| Nome |
Necessario |
Tipo |
Descrizione |
|
query
|
True
|
string
|
Query sulle risorse.
|
|
facets
|
|
FacetRequest[]
|
Matrice di richieste di facet da calcolare in base al risultato della query.
|
|
managementGroups
|
|
string[]
|
Gruppi di gestione di Azure su cui eseguire la query. Esempio: [ 'mg1', 'mg2' ]
|
|
options
|
|
QueryRequestOptions
|
Opzioni di valutazione delle query
|
|
subscriptions
|
|
string[]
|
Sottoscrizioni di Azure su cui eseguire la query.
|
Risposte
Sicurezza
azure_auth
Azure Active Directory OAuth2 Flow.
Tipo:
oauth2
Flow:
implicit
URL di autorizzazione:
https://login.microsoftonline.com/common/oauth2/authorize
Ambiti
| Nome |
Descrizione |
|
user_impersonation
|
rappresentare l'account utente
|
Esempio
Access a properties field
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"query": "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)",
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
]
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_properties_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"query": "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)",
"subscriptions": ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesPropertiesQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesPropertiesQuery.json
func ExampleClient_Resources_accessAPropertiesField() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Query: to.Ptr("Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"),
Subscriptions: []*string{
to.Ptr("cfbbd179-59d2-4052-aa06-9270a38aa9d6"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// Count: to.Ptr[int64](2),
// Data: []any{
// map[string]any{
// "count": 7,
// "properties_storageProfile_osDisk_osType": "Linux",
// },
// map[string]any{
// "count": 23,
// "properties_storageProfile_osDisk_osType": "Windows",
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](2),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesPropertiesQuery.json
*/
async function accessAPropertiesField() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
query:
"Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)",
subscriptions: ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"count": 2,
"data": [
{
"count": 7,
"properties_storageProfile_osDisk_osType": "Linux"
},
{
"count": 23,
"properties_storageProfile_osDisk_osType": "Windows"
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 2
}
Basic management group query
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"managementGroups": [
"e927f598-c1d4-4f72-8541-95d83a6a4ac8",
"ProductionMG"
],
"query": "Resources | project id, name, type, location, tags | limit 3"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_mg_basic_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"managementGroups": ["e927f598-c1d4-4f72-8541-95d83a6a4ac8", "ProductionMG"],
"query": "Resources | project id, name, type, location, tags | limit 3",
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesMgBasicQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesMgBasicQuery.json
func ExampleClient_Resources_basicManagementGroupQuery() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
ManagementGroups: []*string{
to.Ptr("e927f598-c1d4-4f72-8541-95d83a6a4ac8"),
to.Ptr("ProductionMG"),
},
Query: to.Ptr("Resources | project id, name, type, location, tags | limit 3"),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// Count: to.Ptr[int64](3),
// Data: []any{
// map[string]any{
// "name": "myNetworkInterface",
// "type": "microsoft.network/networkinterfaces",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
// "location": "centralus",
// "tags": map[string]any{
// "tag1": "Value1",
// },
// },
// map[string]any{
// "name": "myVnet",
// "type": "microsoft.network/virtualnetworks",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
// "location": "westus",
// "tags": map[string]any{
// },
// },
// map[string]any{
// "name": "myPublicIp",
// "type": "microsoft.network/publicipaddresses",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
// "location": "westus",
// "tags": map[string]any{
// },
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](3),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesMgBasicQuery.json
*/
async function basicManagementGroupQuery() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
managementGroups: ["e927f598-c1d4-4f72-8541-95d83a6a4ac8", "ProductionMG"],
query: "Resources | project id, name, type, location, tags | limit 3",
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"count": 3,
"data": [
{
"name": "myNetworkInterface",
"type": "microsoft.network/networkinterfaces",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
"location": "centralus",
"tags": {
"tag1": "Value1"
}
},
{
"name": "myVnet",
"type": "microsoft.network/virtualnetworks",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
"location": "westus",
"tags": {}
},
{
"name": "myPublicIp",
"type": "microsoft.network/publicipaddresses",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
"location": "westus",
"tags": {}
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 3
}
Basic query
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"query": "Resources | project id, name, type, location, tags | limit 3",
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
]
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_basic_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"query": "Resources | project id, name, type, location, tags | limit 3",
"subscriptions": ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesBasicQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesBasicQuery.json
func ExampleClient_Resources_basicQuery() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Query: to.Ptr("Resources | project id, name, type, location, tags | limit 3"),
Subscriptions: []*string{
to.Ptr("cfbbd179-59d2-4052-aa06-9270a38aa9d6"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// Count: to.Ptr[int64](3),
// Data: []any{
// map[string]any{
// "name": "myNetworkInterface",
// "type": "microsoft.network/networkinterfaces",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
// "location": "centralus",
// "tags": map[string]any{
// "tag1": "Value1",
// },
// },
// map[string]any{
// "name": "myVnet",
// "type": "microsoft.network/virtualnetworks",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
// "location": "westus",
// "tags": map[string]any{
// },
// },
// map[string]any{
// "name": "myPublicIp",
// "type": "microsoft.network/publicipaddresses",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
// "location": "westus",
// "tags": map[string]any{
// },
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](3),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesBasicQuery.json
*/
async function basicQuery() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
query: "Resources | project id, name, type, location, tags | limit 3",
subscriptions: ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"count": 3,
"data": [
{
"name": "myNetworkInterface",
"type": "microsoft.network/networkinterfaces",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
"location": "centralus",
"tags": {
"tag1": "Value1"
}
},
{
"name": "myVnet",
"type": "microsoft.network/virtualnetworks",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
"location": "westus",
"tags": {}
},
{
"name": "myPublicIp",
"type": "microsoft.network/publicipaddresses",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
"location": "westus",
"tags": {}
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 3
}
Basic tenant query
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"query": "Resources | project id, name, type, location, tags | limit 3"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_tenant_basic_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={"query": "Resources | project id, name, type, location, tags | limit 3"},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesTenantBasicQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesTenantBasicQuery.json
func ExampleClient_Resources_basicTenantQuery() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Query: to.Ptr("Resources | project id, name, type, location, tags | limit 3"),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// Count: to.Ptr[int64](3),
// Data: []any{
// map[string]any{
// "name": "myNetworkInterface",
// "type": "microsoft.network/networkinterfaces",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
// "location": "centralus",
// "tags": map[string]any{
// "tag1": "Value1",
// },
// },
// map[string]any{
// "name": "myVnet",
// "type": "microsoft.network/virtualnetworks",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
// "location": "westus",
// "tags": map[string]any{
// },
// },
// map[string]any{
// "name": "myPublicIp",
// "type": "microsoft.network/publicipaddresses",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
// "location": "westus",
// "tags": map[string]any{
// },
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](3),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesTenantBasicQuery.json
*/
async function basicTenantQuery() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
query: "Resources | project id, name, type, location, tags | limit 3",
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"count": 3,
"data": [
{
"name": "myNetworkInterface",
"type": "microsoft.network/networkinterfaces",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
"location": "centralus",
"tags": {
"tag1": "Value1"
}
},
{
"name": "myVnet",
"type": "microsoft.network/virtualnetworks",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
"location": "westus",
"tags": {}
},
{
"name": "myPublicIp",
"type": "microsoft.network/publicipaddresses",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
"location": "westus",
"tags": {}
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 3
}
Complex query
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"query": "Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_",
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
]
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_complex_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"query": "Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_",
"subscriptions": ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesComplexQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesComplexQuery.json
func ExampleClient_Resources_complexQuery() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Query: to.Ptr("Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_"),
Subscriptions: []*string{
to.Ptr("cfbbd179-59d2-4052-aa06-9270a38aa9d6"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// Count: to.Ptr[int64](3),
// Data: []any{
// map[string]any{
// "count_": 11,
// "location": "centralus",
// },
// map[string]any{
// "count_": 11,
// "location": "eastus",
// },
// map[string]any{
// "count_": 3,
// "location": "southcentralus",
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](3),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesComplexQuery.json
*/
async function complexQuery() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
query:
"Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_",
subscriptions: ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"count": 3,
"data": [
{
"count_": 11,
"location": "centralus"
},
{
"count_": 11,
"location": "eastus"
},
{
"count_": 3,
"location": "southcentralus"
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 3
}
Filter resources
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"query": "Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | limit 3",
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
]
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_filter_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"query": "Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | limit 3",
"subscriptions": ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesFilterQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesFilterQuery.json
func ExampleClient_Resources_filterResources() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Query: to.Ptr("Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | limit 3"),
Subscriptions: []*string{
to.Ptr("cfbbd179-59d2-4052-aa06-9270a38aa9d6"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// Count: to.Ptr[int64](3),
// Data: []any{
// map[string]any{
// "name": "myVm1",
// "type": "microsoft.compute/virtualmachines",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/virtualMachines/myVm1",
// "location": "centralus",
// },
// map[string]any{
// "name": "myVirtualMachine",
// "type": "microsoft.compute/virtualmachines",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Compute/virtualMachines/myVirtualMachine",
// "location": "eastus",
// },
// map[string]any{
// "name": "testVm",
// "type": "microsoft.compute/virtualmachines",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG3/providers/Microsoft.Compute/virtualMachines/testVm",
// "location": "eastus",
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](3),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesFilterQuery.json
*/
async function filterResources() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
query:
"Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | limit 3",
subscriptions: ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"count": 3,
"data": [
{
"name": "myVm1",
"type": "microsoft.compute/virtualmachines",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/virtualMachines/myVm1",
"location": "centralus"
},
{
"name": "myVirtualMachine",
"type": "microsoft.compute/virtualmachines",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Compute/virtualMachines/myVirtualMachine",
"location": "eastus"
},
{
"name": "testVm",
"type": "microsoft.compute/virtualmachines",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG3/providers/Microsoft.Compute/virtualMachines/testVm",
"location": "eastus"
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 3
}
First page query
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"options": {
"$skip": 0,
"$top": 3
},
"query": "Resources | where name contains 'test' | project id, name, type, location",
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
]
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_first_page_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"options": {"$skip": 0, "$top": 3},
"query": "Resources | where name contains 'test' | project id, name, type, location",
"subscriptions": ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesFirstPageQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesFirstPageQuery.json
func ExampleClient_Resources_firstPageQuery() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Options: &armresourcegraph.QueryRequestOptions{
Skip: to.Ptr[int32](0),
Top: to.Ptr[int32](3),
},
Query: to.Ptr("Resources | where name contains 'test' | project id, name, type, location"),
Subscriptions: []*string{
to.Ptr("cfbbd179-59d2-4052-aa06-9270a38aa9d6"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// SkipToken: to.Ptr("eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ=="),
// Count: to.Ptr[int64](3),
// Data: []any{
// map[string]any{
// "name": "yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
// "type": "microsoft.compute/disks",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
// "location": "eastus",
// },
// map[string]any{
// "name": "TestAA",
// "type": "microsoft.automation/automationaccounts",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA",
// "location": "westcentralus",
// },
// map[string]any{
// "name": "TestRB",
// "type": "microsoft.automation/automationaccounts/runbooks",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA/runbooks/TestRB",
// "location": "westcentralus",
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](386),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesFirstPageQuery.json
*/
async function firstPageQuery() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
options: { skip: 0, top: 3 },
query: "Resources | where name contains 'test' | project id, name, type, location",
subscriptions: ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ==",
"count": 3,
"data": [
{
"name": "yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
"type": "microsoft.compute/disks",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
"location": "eastus"
},
{
"name": "TestAA",
"type": "microsoft.automation/automationaccounts",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA",
"location": "westcentralus"
},
{
"name": "TestRB",
"type": "microsoft.automation/automationaccounts/runbooks",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA/runbooks/TestRB",
"location": "westcentralus"
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 386
}
Next page query
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"options": {
"$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ=="
},
"query": "Resources | where name contains 'test' | project id, name, type, location",
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
]
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_next_page_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"options": {"$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ=="},
"query": "Resources | where name contains 'test' | project id, name, type, location",
"subscriptions": ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesNextPageQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesNextPageQuery.json
func ExampleClient_Resources_nextPageQuery() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Options: &armresourcegraph.QueryRequestOptions{
SkipToken: to.Ptr("eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ=="),
},
Query: to.Ptr("Resources | where name contains 'test' | project id, name, type, location"),
Subscriptions: []*string{
to.Ptr("cfbbd179-59d2-4052-aa06-9270a38aa9d6"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// SkipToken: to.Ptr("eyAibm8yIjogImx1Y2syIiwgImJ1dDIiOiAibmljZTIiLCAidHJ5MiI6ICIhIiB9"),
// Count: to.Ptr[int64](3),
// Data: []any{
// map[string]any{
// "name": "second_OsDisk_dddddbcb625a457bb69fe2abf5975820",
// "type": "microsoft.compute/disks",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/second_OsDisk_dddddbcb625a457bb69fe2abf5975820",
// "location": "eastus",
// },
// map[string]any{
// "name": "AATest",
// "type": "microsoft.automation/automationaccounts",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/AATest",
// "location": "westcentralus",
// },
// map[string]any{
// "name": "RBTest",
// "type": "microsoft.automation/automationaccounts/runbooks",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA/runbooks/RBTest",
// "location": "westcentralus",
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](386),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesNextPageQuery.json
*/
async function nextPageQuery() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
options: { skipToken: "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ==" },
query: "Resources | where name contains 'test' | project id, name, type, location",
subscriptions: ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"$skipToken": "eyAibm8yIjogImx1Y2syIiwgImJ1dDIiOiAibmljZTIiLCAidHJ5MiI6ICIhIiB9",
"count": 3,
"data": [
{
"name": "second_OsDisk_dddddbcb625a457bb69fe2abf5975820",
"type": "microsoft.compute/disks",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/second_OsDisk_dddddbcb625a457bb69fe2abf5975820",
"location": "eastus"
},
{
"name": "AATest",
"type": "microsoft.automation/automationaccounts",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/AATest",
"location": "westcentralus"
},
{
"name": "RBTest",
"type": "microsoft.automation/automationaccounts/runbooks",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA/runbooks/RBTest",
"location": "westcentralus"
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 386
}
Query with a facet request
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"facets": [
{
"expression": "location",
"options": {
"$top": 3,
"sortOrder": "desc"
}
},
{
"expression": "properties.storageProfile.osDisk.osType",
"options": {
"$top": 3,
"sortOrder": "desc"
}
},
{
"expression": "nonExistingColumn",
"options": {
"$top": 3,
"sortOrder": "desc"
}
},
{
"expression": "resourceGroup",
"options": {
"$top": 3,
"sortBy": "tolower(resourceGroup)",
"sortOrder": "asc"
}
},
{
"expression": "resourceGroup",
"options": {
"$top": 3,
"filter": "resourceGroup contains 'test'"
}
}
],
"query": "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project id, name, location, resourceGroup, properties.storageProfile.osDisk.osType | limit 5",
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
]
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_facet_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"facets": [
{"expression": "location", "options": {"$top": 3, "sortOrder": "desc"}},
{"expression": "properties.storageProfile.osDisk.osType", "options": {"$top": 3, "sortOrder": "desc"}},
{"expression": "nonExistingColumn", "options": {"$top": 3, "sortOrder": "desc"}},
{
"expression": "resourceGroup",
"options": {"$top": 3, "sortBy": "tolower(resourceGroup)", "sortOrder": "asc"},
},
{"expression": "resourceGroup", "options": {"$top": 3, "filter": "resourceGroup contains 'test'"}},
],
"query": "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project id, name, location, resourceGroup, properties.storageProfile.osDisk.osType | limit 5",
"subscriptions": ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesFacetQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesFacetQuery.json
func ExampleClient_Resources_queryWithAFacetRequest() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Facets: []*armresourcegraph.FacetRequest{
{
Expression: to.Ptr("location"),
Options: &armresourcegraph.FacetRequestOptions{
Top: to.Ptr[int32](3),
SortOrder: to.Ptr(armresourcegraph.FacetSortOrderDesc),
},
},
{
Expression: to.Ptr("properties.storageProfile.osDisk.osType"),
Options: &armresourcegraph.FacetRequestOptions{
Top: to.Ptr[int32](3),
SortOrder: to.Ptr(armresourcegraph.FacetSortOrderDesc),
},
},
{
Expression: to.Ptr("nonExistingColumn"),
Options: &armresourcegraph.FacetRequestOptions{
Top: to.Ptr[int32](3),
SortOrder: to.Ptr(armresourcegraph.FacetSortOrderDesc),
},
},
{
Expression: to.Ptr("resourceGroup"),
Options: &armresourcegraph.FacetRequestOptions{
Top: to.Ptr[int32](3),
SortBy: to.Ptr("tolower(resourceGroup)"),
SortOrder: to.Ptr(armresourcegraph.FacetSortOrderAsc),
},
},
{
Expression: to.Ptr("resourceGroup"),
Options: &armresourcegraph.FacetRequestOptions{
Top: to.Ptr[int32](3),
Filter: to.Ptr("resourceGroup contains 'test'"),
},
},
},
Query: to.Ptr("Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project id, name, location, resourceGroup, properties.storageProfile.osDisk.osType | limit 5"),
Subscriptions: []*string{
to.Ptr("cfbbd179-59d2-4052-aa06-9270a38aa9d6"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// Count: to.Ptr[int64](5),
// Data: []any{
// map[string]any{
// "name": "myTestVm",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/B-TEST-RG/providers/Microsoft.Compute/virtualMachines/myTestVm",
// "location": "eastus",
// "properties_storageProfile_osDisk_osType": "Windows",
// "resourceGroup": "B-TEST-RG",
// },
// map[string]any{
// "name": "myTestAccountVm",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/c-rg/providers/Microsoft.Compute/virtualMachines/myTestAccountVm",
// "location": "westcentralus",
// "properties_storageProfile_osDisk_osType": "Windows",
// "resourceGroup": "c-rg",
// },
// map[string]any{
// "name": "yetanothertest",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/I-RG/providers/Microsoft.Compute/virtualMachines/yetanothertest",
// "location": "eastus",
// "properties_storageProfile_osDisk_osType": "Linux",
// "resourceGroup": "I-RG",
// },
// map[string]any{
// "name": "drafttest1bux4cv7a7q3aw",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/x-test-rg/providers/Microsoft.Compute/virtualMachines/drafttest1bux4cv7a7q3aw",
// "location": "southcentralus",
// "properties_storageProfile_osDisk_osType": "Linux",
// "resourceGroup": "x-test-rg",
// },
// map[string]any{
// "name": "testvmntp25370",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/y-rg/providers/Microsoft.Compute/virtualMachines/testvmntp25370",
// "location": "eastus",
// "properties_storageProfile_osDisk_osType": "Windows",
// "resourceGroup": "y-rg",
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// &armresourcegraph.FacetResult{
// Count: to.Ptr[int32](3),
// Data: []any{
// map[string]any{
// "count": 3,
// "location": "eastus",
// },
// map[string]any{
// "count": 1,
// "location": "southcentralus",
// },
// map[string]any{
// "count": 1,
// "location": "westcentralus",
// },
// },
// Expression: to.Ptr("location"),
// ResultType: to.Ptr("FacetResult"),
// TotalRecords: to.Ptr[int64](3),
// },
// &armresourcegraph.FacetResult{
// Count: to.Ptr[int32](2),
// Data: []any{
// map[string]any{
// "count": 2,
// "properties_storageProfile_osDisk_osType": "Linux",
// },
// map[string]any{
// "count": 3,
// "properties_storageProfile_osDisk_osType": "Windows",
// },
// },
// Expression: to.Ptr("properties.storageProfile.osDisk.osType"),
// ResultType: to.Ptr("FacetResult"),
// TotalRecords: to.Ptr[int64](2),
// },
// &armresourcegraph.FacetError{
// Errors: []*armresourcegraph.ErrorDetails{
// {
// Code: to.Ptr("NoValidColumns"),
// Message: to.Ptr("No valid columns in facet expression."),
// },
// {
// Code: to.Ptr("InvalidColumnNames"),
// Message: to.Ptr("Invalid column names: [nonExistingColumn]."),
// },
// },
// Expression: to.Ptr("nonExistingColumn"),
// ResultType: to.Ptr("FacetError"),
// },
// &armresourcegraph.FacetResult{
// Count: to.Ptr[int32](3),
// Data: []any{
// map[string]any{
// "count": 1,
// "resourceGroup": "B-TEST-RG",
// },
// map[string]any{
// "count": 1,
// "resourceGroup": "c-rg",
// },
// map[string]any{
// "count": 1,
// "resourceGroup": "I-RG",
// },
// },
// Expression: to.Ptr("resourceGroup"),
// ResultType: to.Ptr("FacetResult"),
// TotalRecords: to.Ptr[int64](5),
// },
// &armresourcegraph.FacetResult{
// Count: to.Ptr[int32](2),
// Data: []any{
// map[string]any{
// "count": 1,
// "resourceGroup": "B-TEST-RG",
// },
// map[string]any{
// "count": 1,
// "resourceGroup": "x-test-rg",
// },
// },
// Expression: to.Ptr("resourceGroup"),
// ResultType: to.Ptr("FacetResult"),
// TotalRecords: to.Ptr[int64](2),
// },
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](5),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesFacetQuery.json
*/
async function queryWithAFacetRequest() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
facets: [
{ expression: "location", options: { top: 3, sortOrder: "desc" } },
{
expression: "properties.storageProfile.osDisk.osType",
options: { top: 3, sortOrder: "desc" },
},
{ expression: "nonExistingColumn", options: { top: 3, sortOrder: "desc" } },
{
expression: "resourceGroup",
options: { top: 3, sortBy: "tolower(resourceGroup)", sortOrder: "asc" },
},
{ expression: "resourceGroup", options: { top: 3, filter: "resourceGroup contains 'test'" } },
],
query:
"Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project id, name, location, resourceGroup, properties.storageProfile.osDisk.osType | limit 5",
subscriptions: ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"count": 5,
"data": [
{
"name": "myTestVm",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/B-TEST-RG/providers/Microsoft.Compute/virtualMachines/myTestVm",
"location": "eastus",
"properties_storageProfile_osDisk_osType": "Windows",
"resourceGroup": "B-TEST-RG"
},
{
"name": "myTestAccountVm",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/c-rg/providers/Microsoft.Compute/virtualMachines/myTestAccountVm",
"location": "westcentralus",
"properties_storageProfile_osDisk_osType": "Windows",
"resourceGroup": "c-rg"
},
{
"name": "yetanothertest",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/I-RG/providers/Microsoft.Compute/virtualMachines/yetanothertest",
"location": "eastus",
"properties_storageProfile_osDisk_osType": "Linux",
"resourceGroup": "I-RG"
},
{
"name": "drafttest1bux4cv7a7q3aw",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/x-test-rg/providers/Microsoft.Compute/virtualMachines/drafttest1bux4cv7a7q3aw",
"location": "southcentralus",
"properties_storageProfile_osDisk_osType": "Linux",
"resourceGroup": "x-test-rg"
},
{
"name": "testvmntp25370",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/y-rg/providers/Microsoft.Compute/virtualMachines/testvmntp25370",
"location": "eastus",
"properties_storageProfile_osDisk_osType": "Windows",
"resourceGroup": "y-rg"
}
],
"facets": [
{
"count": 3,
"data": [
{
"count": 3,
"location": "eastus"
},
{
"count": 1,
"location": "southcentralus"
},
{
"count": 1,
"location": "westcentralus"
}
],
"expression": "location",
"resultType": "FacetResult",
"totalRecords": 3
},
{
"count": 2,
"data": [
{
"count": 2,
"properties_storageProfile_osDisk_osType": "Linux"
},
{
"count": 3,
"properties_storageProfile_osDisk_osType": "Windows"
}
],
"expression": "properties.storageProfile.osDisk.osType",
"resultType": "FacetResult",
"totalRecords": 2
},
{
"errors": [
{
"code": "NoValidColumns",
"message": "No valid columns in facet expression."
},
{
"code": "InvalidColumnNames",
"message": "Invalid column names: [nonExistingColumn]."
}
],
"expression": "nonExistingColumn",
"resultType": "FacetError"
},
{
"count": 3,
"data": [
{
"count": 1,
"resourceGroup": "B-TEST-RG"
},
{
"count": 1,
"resourceGroup": "c-rg"
},
{
"count": 1,
"resourceGroup": "I-RG"
}
],
"expression": "resourceGroup",
"resultType": "FacetResult",
"totalRecords": 5
},
{
"count": 2,
"data": [
{
"count": 1,
"resourceGroup": "B-TEST-RG"
},
{
"count": 1,
"resourceGroup": "x-test-rg"
}
],
"expression": "resourceGroup",
"resultType": "FacetResult",
"totalRecords": 2
}
],
"resultTruncated": "false",
"totalRecords": 5
}
Random page query
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"options": {
"$skip": 10,
"$top": 2
},
"query": "Resources | where name contains 'test' | project id, name, type, location",
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
]
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_random_page_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"options": {"$skip": 10, "$top": 2},
"query": "Resources | where name contains 'test' | project id, name, type, location",
"subscriptions": ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesRandomPageQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesRandomPageQuery.json
func ExampleClient_Resources_randomPageQuery() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Options: &armresourcegraph.QueryRequestOptions{
Skip: to.Ptr[int32](10),
Top: to.Ptr[int32](2),
},
Query: to.Ptr("Resources | where name contains 'test' | project id, name, type, location"),
Subscriptions: []*string{
to.Ptr("cfbbd179-59d2-4052-aa06-9270a38aa9d6"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// SkipToken: to.Ptr("eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ=="),
// Count: to.Ptr[int64](2),
// Data: []any{
// map[string]any{
// "name": "third_OsDisk_dddddbcb625a457bb69fe2abf5975820",
// "type": "microsoft.compute/disks",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/third_OsDisk_dddddbcb625a457bb69fe2abf5975820",
// "location": "eastus",
// },
// map[string]any{
// "name": "CCTest",
// "type": "microsoft.automation/automationaccounts",
// "id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/CCTest",
// "location": "westcentralus",
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](386),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesRandomPageQuery.json
*/
async function randomPageQuery() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
options: { skip: 10, top: 2 },
query: "Resources | where name contains 'test' | project id, name, type, location",
subscriptions: ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ==",
"count": 2,
"data": [
{
"name": "third_OsDisk_dddddbcb625a457bb69fe2abf5975820",
"type": "microsoft.compute/disks",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/third_OsDisk_dddddbcb625a457bb69fe2abf5975820",
"location": "eastus"
},
{
"name": "CCTest",
"type": "microsoft.automation/automationaccounts",
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/CCTest",
"location": "westcentralus"
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 386
}
Summarize resources by location
Esempio di richiesta
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"query": "Resources | project id, name, type, location | summarize by location",
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
]
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.resourcegraph import ResourceGraphClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resourcegraph
# USAGE
python resources_summarize_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ResourceGraphClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.resources(
query={
"query": "Resources | project id, name, type, location | summarize by location",
"subscriptions": ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
},
)
print(response)
# x-ms-original-file: 2024-04-01/ResourcesSummarizeQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armresourcegraph_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)
// Generated from example definition: 2024-04-01/ResourcesSummarizeQuery.json
func ExampleClient_Resources_summarizeResourcesByLocation() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
Query: to.Ptr("Resources | project id, name, type, location | summarize by location"),
Subscriptions: []*string{
to.Ptr("cfbbd179-59d2-4052-aa06-9270a38aa9d6"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armresourcegraph.ClientResourcesResponse{
// QueryResponse: armresourcegraph.QueryResponse{
// Count: to.Ptr[int64](3),
// Data: []any{
// map[string]any{
// "location": "centralus",
// },
// map[string]any{
// "location": "eastus",
// },
// map[string]any{
// "location": "westus",
// },
// },
// Facets: []armresourcegraph.FacetClassification{
// },
// ResultTruncated: to.Ptr(armresourcegraph.ResultTruncatedFalse),
// TotalRecords: to.Ptr[int64](3),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceGraphClient } = require("@azure/arm-resourcegraph");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to queries the resources managed by Azure Resource Manager for scopes specified in the request.
*
* @summary queries the resources managed by Azure Resource Manager for scopes specified in the request.
* x-ms-original-file: 2024-04-01/ResourcesSummarizeQuery.json
*/
async function summarizeResourcesByLocation() {
const credential = new DefaultAzureCredential();
const client = new ResourceGraphClient(credential);
const result = await client.resources({
query: "Resources | project id, name, type, location | summarize by location",
subscriptions: ["cfbbd179-59d2-4052-aa06-9270a38aa9d6"],
});
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Risposta di esempio
{
"count": 3,
"data": [
{
"location": "centralus"
},
{
"location": "eastus"
},
{
"location": "westus"
}
],
"facets": [],
"resultTruncated": "false",
"totalRecords": 3
}
Definizioni
AuthorizationScopeFilter
Enumerazione
Definisce il livello di risorse di autorizzazione da restituire in base alle sottoscrizioni e ai gruppi di gestione passati come ambiti.
| Valore |
Descrizione |
|
AtScopeAndBelow
|
AtScopeAndBelow
|
|
AtScopeAndAbove
|
AtScopeAndAbove
|
|
AtScopeExact
|
AtScopeExact
|
|
AtScopeAboveAndBelow
|
AtScopeAbove BelowBelow
|
FacetError
Oggetto
Facet la cui esecuzione ha generato un errore.
| Nome |
Tipo |
Descrizione |
|
errors
|
ResourceGraphCommon.ErrorDetails[]
|
Matrice contenente gli errori di facet rilevati con i dettagli.
|
|
expression
|
string
|
Espressione facet, come nella richiesta facet corrispondente.
|
|
resultType
|
string:
FacetError
|
Tipo di risultato
|
FacetRequest
Oggetto
Richiesta di calcolo di statistiche aggiuntive (facet) sui risultati della query.
| Nome |
Tipo |
Descrizione |
|
expression
|
string
|
Colonna o elenco di colonne da riepilogare
|
|
options
|
FacetRequestOptions
|
Opzioni per la valutazione facet
|
FacetRequestOptions
Oggetto
Opzioni per la valutazione facet
| Nome |
Tipo |
Valore predefinito |
Descrizione |
|
$top
|
integer
(int32)
minimum: 1 maximum: 1000
|
|
Numero massimo di righe di facet che devono essere restituite.
|
|
filter
|
string
|
|
Specifica la condizione di filtro per la clausola 'where' che verrà eseguita sul risultato della query principale, subito prima del facet effettivo.
|
|
sortBy
|
string
|
|
Nome della colonna o espressione di query su cui eseguire l'ordinamento. L'impostazione predefinita viene conteggiato se non presente.
|
|
sortOrder
|
FacetSortOrder
|
desc
|
Ordinamento in base alla colonna selezionata (conteggio per impostazione predefinita).
|
FacetResult
Oggetto
Facet eseguito correttamente contenente statistiche aggiuntive sulla risposta di una query.
| Nome |
Tipo |
Descrizione |
|
count
|
integer
(int32)
|
Numero di record restituiti nella risposta facet.
|
|
data
|
|
Matrice JObject o Tabella contenente i facet desiderati. Presente solo se il facet è valido.
|
|
expression
|
string
|
Espressione facet, come nella richiesta facet corrispondente.
|
|
resultType
|
string:
FacetResult
|
Tipo di risultato
|
|
totalRecords
|
integer
(int64)
|
Numero di record totali nei risultati del facet.
|
FacetSortOrder
Enumerazione
Ordinamento in base alla colonna selezionata (conteggio per impostazione predefinita).
| Valore |
Descrizione |
|
asc
|
Asc
|
|
desc
|
descrizione
|
QueryRequest
Oggetto
Descrive una query da eseguire.
| Nome |
Tipo |
Descrizione |
|
facets
|
FacetRequest[]
|
Matrice di richieste di facet da calcolare in base al risultato della query.
|
|
managementGroups
|
string[]
|
Gruppi di gestione di Azure su cui eseguire la query. Esempio: [ 'mg1', 'mg2' ]
|
|
options
|
QueryRequestOptions
|
Opzioni di valutazione delle query
|
|
query
|
string
|
Query sulle risorse.
|
|
subscriptions
|
string[]
|
Sottoscrizioni di Azure su cui eseguire la query.
|
QueryRequestOptions
Oggetto
Opzioni per la valutazione delle query
| Nome |
Tipo |
Valore predefinito |
Descrizione |
|
$skip
|
integer
(int32)
minimum: 0
|
|
Numero di righe da ignorare dall'inizio dei risultati. Esegue l'override dell'offset di pagina successivo quando è presente $skipToken proprietà .
|
|
$skipToken
|
string
|
|
Token di continuazione per la paginazione, acquisizione delle dimensioni e dell'offset della pagina successiva, nonché il contesto della query.
|
|
$top
|
integer
(int32)
minimum: 1 maximum: 1000
|
|
Numero massimo di righe restituite dalla query. Esegue l'override delle dimensioni della pagina quando è presente $skipToken proprietà .
|
|
allowPartialScopes
|
boolean
|
False
|
Applicabile solo alle query a livello di tenant e di gruppo di gestione per decidere se consentire ambiti parziali per il risultato nel caso in cui il numero di sottoscrizioni superi i limiti consentiti.
|
|
authorizationScopeFilter
|
AuthorizationScopeFilter
|
AtScopeAndBelow
|
Definisce il livello di risorse di autorizzazione da restituire in base alle sottoscrizioni e ai gruppi di gestione passati come ambiti.
|
|
resultFormat
|
ResultFormat
|
objectArray
|
Definisce in quale formato viene restituito il risultato della query.
|
QueryResponse
Oggetto
Risultato della query.
| Nome |
Tipo |
Descrizione |
|
$skipToken
|
string
|
Quando presente, il valore può essere passato a una chiamata di query successiva (insieme alla stessa query e agli stessi ambiti usati nella richiesta corrente) per recuperare la pagina successiva dei dati.
|
|
count
|
integer
(int64)
|
Numero di record restituiti nella risposta corrente. Nel caso del paging, si tratta del numero di record nella pagina corrente.
|
|
data
|
|
Output della query in formato JObject o Tabella.
|
|
facets
|
Facet[]:
|
Facet di query.
|
|
resultTruncated
|
ResultTruncated
|
Indica se i risultati della query vengono troncati.
|
|
totalRecords
|
integer
(int64)
|
Numero di record totali corrispondenti alla query.
|
ResourceGraphCommon.Error
Oggetto
Informazioni sull'errore.
| Nome |
Tipo |
Descrizione |
|
code
|
string
|
Codice di errore che identifica l'errore specifico.
|
|
details
|
ResourceGraphCommon.ErrorDetails[]
|
Dettagli errore
|
|
message
|
string
|
Messaggio di errore leggibile.
|
ResourceGraphCommon.ErrorDetails
Oggetto
Dettagli errore.
| Nome |
Tipo |
Descrizione |
|
code
|
string
|
Codice di errore che identifica l'errore specifico.
|
|
message
|
string
|
Messaggio di errore leggibile.
|
ResourceGraphCommon.ErrorResponse
Oggetto
Risposta di errore.
Enumerazione
Definisce in quale formato viene restituito il risultato della query.
| Valore |
Descrizione |
|
table
|
table
|
|
objectArray
|
objectArray
|
ResultTruncated
Enumerazione
Indica se i risultati della query vengono troncati.
| Valore |
Descrizione |
|
true
|
true
|
|
false
|
falso
|