I am trying to create an Azure monitor alert rule using REST API.
Using this link to exercise the same: https://learn.microsoft.com/en-us/rest/api/monitor/alert-rules/create-or-update?view=rest-monitor-2016-03-01
Upon doing the same i am getting error like below:
{
"code": "UnsupportedRequestContent",
"message": "Request content is not well formed or supported."
}
Payload is as follows:
{
"location": "westus",
"properties": {
"description": "Test Alert",
"isEnabled": "true",
"severity": 2,
"evaluationFrequency": "PT1M",
"windowSize": "PT5M",
"condition": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"name": "metric1",
"metricNamespace": "Microsoft.CognitiveServices/accounts",
"metricName": "TokenTransaction",
"operator": "GreaterThan",
"threshold": 50000,
"timeAggregation": "Average",
"dimensions": [
{
"name": "FeatureName",
"operator": "Include",
"values": [
"gpt-4"
]
}
]
}
]
},
"actions": [],
"scopes": [
"/subscriptions/subid/resourceGroups/tgname/providers/Microsoft.CognitiveServices/accounts/openainame"
]
}
}
Other details:
PUT https://management.azure.com/subscriptions/subid/resourcegroups/rgname/providers/Microsoft.Insights/alertrules/rulename?api-version=2016-03-01
Authorization: Bearer Token
Content-type: application/json
I dont find any microsoft documents to explain the right payload data, Any sample data to create Metric rule is really appreciated.
When I ran below API call with your request body in my environment, I too got same error:
Response:
To resolve the error, make use of below API call with modified request body like this:
Response:
To confirm that, I checked the same in Portal where alert rule created successfully for Azure OpenAI account scope like this:
Reference: Metric Alerts - Create Or Update - REST API (Azure Monitor) | Microsoft