I’m trying to automate the creation of alert conditions for our alert policy using PowerShell and am having trouble converting the syntax from the CURL example found on the API documentation site to PowerShell. My PowerShell is below. Does anyone happen to see what I’m doing wrong? It seems to be an issue in the terms array based on the error I’m getting back but I’m unsure as to what’s wrong. Thanks.
$body = @{
condition = @{
type = "apm_app_metric"
name = "TEST Condition"
enabled = $true
entities = @(##MY_ENTITY_ID##)
metric = "apdex"
condition_scope = "application"
terms = @(
@{
duration = "15"
operator = "below"
priority = "critical"
threshold = "0.5"
time_function = "all"
}
)
}
}
$response = Invoke-WebRequest "https://api.newrelic.com/v2/alerts_conditions/policies/$($policyId).json" `
-Method Post `
-ContentType "application/json" `
-Headers @{"X-Api-Key" = $adminApiKey} `
-Body (ConvertTo-Json $body)