Rest API integration close alert based on alias
Asked by Charalampos Kailantzis:

Hi there,

I'm trying to replicate similar behaviour to this question behaviour <https://community.atlassian.com/t5/Opsgenie-questions/Can-we-close-alerts-in-Opsgenie-with-email-integration/qaq-p/1642680>, but in the case using the REST API integration, using the following settings

message sample (ERROR)**: \[Product Environment\] A-Service: ERROR**

message sample (SUCCESS): **\[Product Environment\] A-Service: SUCCESS**

![Screenshot 2021-09-22 at 21.56.27.png](https://community.atlassian.com/t5/image/serverpage/image-id/161630iB60693D7BBB62D75/image-size/large?v=v2&px=999 "Screenshot 2021-09-22 at 21.56.27.png")![Screenshot 2021-09-22 at 21.56.49.png](https://community.atlassian.com/t5/image/serverpage/image-id/161631i653C8D644A6025C1/image-size/large?v=v2&px=999 "Screenshot 2021-09-22 at 21.56.49.png")

The idea is to create an alert with message contains ERROR,

Close the error alert with same alias when new message contains SUCCESS

Creation on ERROR works fine, but for SUCCESS message it logs "Can not execute alert action. Incoming data does not match any actions." and alias in this case is empty "" + and previous ERROR alert remains open of course.

Any advice/hints on what I'm doing wrong ? See attached screenshots.

Thanks in advance.


Answers:
author: Nick H
body: Hi [@Charalampos Kailantzis](/t5/user/viewprofilepage/user-id/4568885) ,

I believe your issue is be due to the Rest API using a different URL or endpoint to close and alert vs. creating one: <https://docs.opsgenie.com/docs/alert-api#close-alert>

And what I *believe*is happening is the request being sent Opsgenie is probably using the URL to create an alert - so that error in the logs would make sense with no matching action found in the Create Alert action.

The URL needed to close the alert might be something like:

<https://api.opsgenie.com/v2/alerts/%5BProduct%20Environment%5D%20A-Service/close?identifierType=alias>

or one of the other options we have available to close an alert through the API. Here's a test as well for example through Postman:

![apicomm1.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/161639i07FB755D72DB7C74/image-size/large?v=v2&px=999 "apicomm1.jpg")![apicomm2.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/161638i203138D5BE69425B/image-size/large?v=v2&px=999 "apicomm2.jpg")![apicomm3.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/161640i2BDA33B53282C2E7/image-size/large?v=v2&px=999 "apicomm3.jpg")

Hope that helps! Let us know if you have any other questions.

comments: author: Charalampos Kailantzis
body: Checking now the logs more carefully:

* alias \[Product Environment\] A-Service
* message \[Product Environment\] A-Service: ERROR

any idea why the message still contains "ERROR", when in the body I have "SUCCESS". ??. Or I'm missing something ? I'm also using Postman for testing this.


author: Nick H
body: Closing the alert through the API would not change the message of the alert. You could update the alert's message through an API call or in the UI: <https://docs.opsgenie.com/docs/alert-api-continued#update-alert-message>


author: Charalampos Kailantzis
body: HI [@Nick H](/t5/user/viewprofilepage/user-id/2540930) ,

Understood. But in your example screenshot in postman, I see a 'message' field defined in the body for 'close' alert call, or I'm seeing it in the wrong way ?

The use case behind my question, is that there is a custom monitoring 'ERROR' and 'SUCCESS' solution for various services and environments that creates alerts in opsgenie when a service is Down. The question was how to make use of the rest API integration filters/conditions then in order to close an ERROR alert when same service is up again. Is it possible only via the close alert api ?


author: Nick H
body: That is correct - in my example I defined the message field in the close alert request body.

But I'm realizing that the Close Alert action of the API integration might not be able to filter on the Message of the alert - so I do apologize for misleading you here. It's different than other integrations - like the Email integration with the other community post you shared.

You could alternatively have the Close Alert action act like a catch-all - matching on all alerts that do not match on a Create Alert action, and that would work through an API request:

![apicpmm6.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/161792iAC8B7939D6820A8B/image-size/large?v=v2&px=999 "apicpmm6.jpg")


author: Charalampos Kailantzis
body: Hi [@Nick H](/t5/user/viewprofilepage/user-id/2540930)

Thanks for the clarification.

I tried the close api alert with the filter set to "match all alerts", even set the allias field to: {{alias}}, for the close action, instead of the substring function, and the alert was closed successfully (with empty body payload).

Thanks for your help!


author: Charalampos Kailantzis
body: hi [@Nick H](/t5/user/viewprofilepage/user-id/2540930) ,

thanks for your reply. I changed the call to the close alert, and used exaclty same paradigm. So while I still see the  
"result": "Request will be processed"  
in the response of the 'Close" api call. still the message is the same in the logs "Can not execute alert action. Incoming data does not match any actions.".  
Message sample that I sent is:  
"\[Product Environment\] A-Service: SUCCESS"  
which means, that the alias is found I guess, is just a problem with the rules/conditions in the integration maybe ?  
Thank you.


Tags: cloud