The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Alerts API - Close Alert

Robert Williams
February 26, 2021

I've made a few successful API calls using the same integration key (Get Alerts, Update Description, Add Tag), but while trying to CLOSE ALERT, I get "The remote server returned an error: (400) Bad Request"

Any idea what I could be missing here?

<SNIP>

PS C:\> $closeAlertURL
https://api.opsgenie.com/v2/alerts/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-xxxxxxxxxxxxx/close

PS C:\> Invoke-RestMethod -Method POST -Uri $closeAlertURL -Headers $global:OpsGenieAPIHeader

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:1 char:1
+ Invoke-RestMethod -Method POST -Uri $closeAlertURL -Headers $global:O ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

<SNIP>

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Robert Williams
February 26, 2021

I figured out the problem.

Even though I'm not using any of the OPTIONAL fields in the JSON body, I MUST have an empty JSON body passed with the request.

Here's what worked for me:

<SNIP>

PS C:\Windows\System32> $closeAlertURL
https://api.opsgenie.com/v2/alerts/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-xxxxxxxxxxxxx/close

PS C:\> $post_message = @{}
$post_message_JSON = $post_message | ConvertTo-Json

PS C:\> Invoke-RestMethod -Method POST -Uri $closeAlertURL -Headers $global:OpsGenieAPIHeader -Body $post_message_JSON

</SNIP>

DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events