How to restrict Resources count in GET request in

2019-08-04 10:14发布

How to filter the resources count in GET Request in AzureRM ?

For an example in List Virtual Machines in an subscription . We get all the Vm's running in an account .

But I need to get 10 VM's alone in ascending or any sorting order . Is there any filter available like that ?

2条回答
做个烂人
2楼-- · 2019-08-04 10:47

You could use the following API.

https://management.azure.com/subscriptions/**********/providers/Microsoft.Compute/virtualmachines?api-version=2017-12-01&top=10

Using $top=10 to filter the top 10 result. See this example.

查看更多
一夜七次
3楼-- · 2019-08-04 11:02

If the sorting order does not matter for you, you can filter the resource count for the top 10 VMs in the GET request below:

I've tried the requests below and tweak resource count for filtering and they all worked as expected.

https://management.azure.com/subscriptions/{subscriptionId}/resources?$filter=resourceType eq 'Microsoft.Compute/virtualmachines'&$top=10&api-version={apiVersion}

Sample response is like below:

{
    "value": [
        {
            "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm}",
            "name": "{vm}",
            "type": "Microsoft.Compute/virtualMachines",
            "location": "{location}"
        },
        {
            "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm}",
            "name": "{vm}",
            "type": "Microsoft.Compute/virtualMachines",
            "location": "{location}"
        }
    ]
}

Hope this helps.

查看更多
登录 后发表回答