How do I retrieve azure monitor metric alerts through Metric Alert - Get API?

MD Saif 1 Reputation point
2021-04-01T13:28:19.43+00:00

I am using the below mentioned API to get the metric alerts (under Azure Monitor) that I created through Azure Portal.

"GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}?api-version=2018-03-01"

In the azure monitor section, under Alerts I can see there are 4 alerts, but I am not able to fetch their information through the API. It is giving me this error:

{
"error": {
"code": "AuthorizationFailed"
"message": "The client {client id} with object id {object id} does not have authorization to perform action 'Microsoft.Insights/metricAlerts/read' over scope '/subscriptions/{SubscriptionID}/resourceGroups/{Resource Group name}/providers/Microsoft.Insights/metricAlerts/{rule name}' or the scope is invalid. If access was recently granted, please refresh your credentials."
}
}

Also can you please let me know if there is a latency in getting the metric alert data through the API?

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,799 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Stanislav Zhelyazkov 21,101 Reputation points MVP
    2021-04-01T13:35:50.557+00:00

    Hi,
    Seems you have authorization problem. Are you sure that the account you have logged to execute that get operation has read permissions for the scope?