Create Alert powershell


#1

I have a script that works creating a new alert. But I am having problems creating a ticket and assigning it to a team. Here is the code that works…

$body = @{
“message”=“An example alert message”;
“alias”=“Life is too short for no alias”;
“description”=“Every alert needs a description”
}
$url="https://api.opsgenie.com/v2/alerts?apiKey=myprivatekey"
Invoke-RestMethod -Method Post -ContentType “application/json” -Uri $url -Body (ConvertTo-Json $body)


#2

There are few different ways:

  • If the api key that you are using belongs to a team integration, then the alert would be automatically routed to that team.
  • If api key is for a global integration, then you can set the team in the teams field of the integration
  • You can set the teams in the body of the alert as you do for message, alias etc. Teams field expect a list so the syntax would be a bit different than the string fields like message. You can find more info on the create alert request in the api docs https://docs.opsgenie.com/docs/alert-api#section-create-alert