Jack
Jack

Reputation: 241

Can't get metrics from Azure REST API

I'm sending a Postman request to get the metrics from an event grid like this:

https://management.azure.com/subscriptions/{suscription id}/resourceGroups/{name of resource group}/providers/microsoft.insights/metricDefinitions/?api-version=2018-01-01

I'm also attaching the Bearer token.

However, I keep getting the following response:

{
    "message": "An error has occurred.",
    "exceptionMessage": "ApiVersion: 2018-01-01 does not support query at non Arm resource Id level",
    "exceptionType": "Microsoft.Online.Metrics.MetricsMP.Utilities.RPRequestFormatException",
    "stackTrace": "   at Microsoft.Online.Metrics.MetricsMP.Controllers.MPController_MetricDefinitions_Base.<MetricDefinitionAtResourceGroup>d__4.MoveNext() in ...
                    ....
}

What does that mean and how can I fix it? I've been looking on the Internet and there's not much information.

Upvotes: 0

Views: 1742

Answers (3)

Joy Wang
Joy Wang

Reputation: 42153

You missed the resource type and name in the request url, the url should be like below:

https://management.azure.com/{resourceUri}/providers/microsoft.insights/metricDefinitions

Reference: https://learn.microsoft.com/en-us/rest/api/monitor/metricdefinitions/list

If you want to list metric definitions of an event grid, your url should be:

GET https://management.azure.com/subscriptions/{subscription id}/resourceGroups/{resource group name}/providers/Microsoft.EventGrid/topics/{event grid topic name}/providers/microsoft.insights/metricDefinitions?api-version=2018-01-01

Test result:

enter image description here

Upvotes: 1

Balasubramaniam
Balasubramaniam

Reputation: 421

To get the metric definitions use this rest API

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resource ProviderNamespace}/{resource Type}/{resourceName}/providers/microsoft.insights/metricdefinitions?api-version=2018-01-01

To get the metrics with optional parameters use this rest API

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/metrics?timespan={timeSpan}&interval={timeGranularity}&aggregation={AggregationType}&metricnames={metricName}&api-version=2018-01-01

Upvotes: 1

Jim Xu
Jim Xu

Reputation: 23141

Your URL is wrong.As far as I know,if you want to retrieve metric definitions, the rest api is that

Method: GET

Request URI: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}/providers/microsoft.insights/metricDefinitions?api-version={apiVersion}

For more details, please refer to

https://learn.microsoft.com/en-us/rest/api/monitor/metricdefinitions/metricdefinitions_list https://learn.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-rest-api-walkthrough.

Upvotes: 2

Related Questions