Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Acknowledge alert from the API

Xana
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 30, 2022

I need some advise regarding acknowledging alerts using the API.
I have been using this link as reference https://docs.opsgenie.com/docs/alert-api#acknowledge-alert

I am currently using PowerShell to get alerts successfully and then run some action offline.

As part of my post actions, I would like to acknowledge the alert but I'm not having much luck with that. I do suspect I'm doing it wrong. 

This is what I'm currently using to try and acknowledge the alert:

 

$opsGenieBaseURi = 'https://api.eu.opsgenie.com/v2/'
$apikey = 'mysecretkey'
$Headers = @{
            'Authorization' = "GenieKey $($apiKey)"
            'ContentType' = 'application/json'
             }

$request_uri = "alerts/38565/acknowledge?identifierType=tiny"
Invoke-RestMethod -Uri ($opsGenieBaseURi+$request_uri) -Headers $headers -Method POST
The error:
Invoke-RestMethod: {"message":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported","took":0.001,"requestId":

 

 

2 answers

1 accepted

0 votes
Answer accepted
Nick H
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 30, 2022

Hi @Xana ,

I think it might be as simple an incorrect header? 

Looks like yours is "ContentType"

While I believe it should be "Content-Type"

https://docs.opsgenie.com/docs/alert-api#acknowledge-alert

Xana
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 31, 2022

That does seem to be the problem. 

Thanks

0 votes
Areif Mohamed
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 13, 2024

@Nick H ,

 

I am using opsgenie python SDK (opsgenie-sdk==2.1.5) to Acknowledge alert, but I get "Body should be a JSON object" error response. 

 

My function calling acknowledge_alert: 

 

def acknowledgeAlert(self, request_id):
try:
response = self.alert_api.acknowledge_alert(identifier=request_id, identifier_type='id')
print("request status response :", response)

Response:
Traceback (most recent call last):
File "/Users/areif/Phoenix_Projects/victor_git/opsgenie_client_api/client.py", line 496, in <module>
response = opsgenie_client.acknowledgeAlert(request_id=alert)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/areif/Phoenix_Projects/victor_git/opsgenie_client_api/client.py", line 399, in acknowledgeAlert
response = self.alert_api.acknowledge_alert(identifier=request_id, identifier_type='id')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/opsgenie_sdk/api/alert/__init__.py", line 62, in acknowledge_alert
(data) = self.acknowledge_alert_with_http_info(identifier, **kwargs) # noqa: E501
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/opsgenie_sdk/api/alert/__init__.py", line 129, in acknowledge_alert_with_http_info
return self.api_client.call_api(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/opsgenie_sdk/api_client.py", line 423, in call_api
return self.__call_api(resource_path, method,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/opsgenie_sdk/api_client.py", line 251, in __call_api
raise exception
opsgenie_sdk.exceptions.ConfigurationException: You have configured something incorrectly: (400)
Reason: Bad Request: Invalid JSON body
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Date': 'Thu, 13 Jun 2024 11:46:55 GMT', 'X-Response-Time': '0.001', 'X-Ratelimit-State': 'OK', 'Og-Apigw-Request-Id': 'd179996e-b207-47b5-8ea4-67d3f801cd2f', 'Server': 'AtlassianEdge', 'X-Content-Type-Options': 'nosniff', 'X-Xss-Protection': '1; mode=block', 'Atl-Traceid': 'fc20c2cc0ae445b88a25a9cac2efb9ce', 'Strict-Transport-Security': 'max-age=63072000; preload', 'Report-To': '{"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}', 'Nel': '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}', 'Vary': 'Accept-Encoding', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 4850de46ab8614f257b88a6151d83804.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'BOM78-P5', 'X-Amz-Cf-Id': 'zTxUaxfra01X5KXRx6n1SPs3wP_kODE2bvCaCsC1M7UmCoVO-o_9yg=='})
HTTP response body: {"message": "Body should be a JSON object", "took": 0.001, "requestId": "20d2d8e5-04df-4669-a01a-0d2dd13ca963", "url": "https://api.opsgenie.com/v2/alerts/2a850d03-3a77-4db3-bb4a-96ac70b9748c-1718278346086/acknowledge"}
I call similar API get_alert, which works fine,
try:
get_response = self.alert_api.get_alert(identifier=alert_id, identifier_type='id')
return get_response
except opsgenie_sdk.ApiException as err:
print("Exception when calling AlertApi->get_alert: %s\n" % err)

 

Only difference I find in the APIs is get_alert is GET and acknowledge_alert is POST. 

Areif Mohamed
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 13, 2024

I was able to successfully ACK alerts from API, after passing  acknowledge_alert_payload={}. I think this is required as this is POST API and some form of body is required.

 

def acknowledgeAlert(self, request_id):
try:
response = self.alert_api.acknowledge_alert(identifier=request_id, identifier_type='id', acknowledge_alert_payload={})
print("request status response :", response)

return response
except opsgenie_sdk.ApiException as err:
print("Exception when calling AlertApi->get request status: %s\n" % err)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events