I'm trying to close an alert using the API based on its alias.
The alert looks like this:
I'm trying to close it by sending a POST request to `https://api.opsgenie.com/v2/alerts/test-luis-6%20-%20warning%20-%20/close?identifierType=alias`. (Removed the last past of the alias because it has identifier info).
The alias I'm sending in the request is exactly the same as in the alert.
I have tried sending the POST request with an empty (`{}`) body, as well as with all the fields filled:
```
{
"note": "Closed automatically by alert-manager lambda",
"user": "alert-manager",
"source": "alert-manager",
}
```
I all cases, I receive the following response:
```
{"result":"Request will be processed","took":0.007,"requestId":"some-id"}
```
But the alert is not closed.
I don't know what I could be doing wrong, or how to debug this.
@Luis Helder , because you're sending the alias in the URL, the "%20" character sequences are probably getting URL-decoded to spaces. By the time it gets to Opsgenie, the alias has become "test-luis-6 - warning - ". To keep the literal "%20"s in your URL, you may have to escape the percent signs. To do that, try replacing each '%' with '%25', the URL-encoding for a sign percent sign. "test-luis-6%2520-%2520warning%2520-%2520"
Hi @Luis Helder ,
I think it might have something to do with the incorrect URL being used, and what you are querying for the alias. For example in our alert API doc, this is the example used:
curl -X POST https://api.opsgenie.com/v2/alerts/life%20is%20too%20short%20for%20no%20alias/close?identifierType=alias -H "Authorization: GenieKey eb243592-faa2-4ba2-a551q-1afdf565c889" -H "Content-Type: application/json" -d '{ "user":"Monitoring Script", "source":"AWS Lambda", "note":"Action executed via Alert API" }'
Where the alias of the alert would be, "life is too short for no alias" - and the %20's in the URL are encoding the spaces.
Your alias actually includes these characters, and some special characters might need to be accounted for as well. I typically use something like this to test what the URL might be: https://www.urlencoder.org/
If we enter what you have, it might be something like this:
As a side note, you will want to send the POST request with an empty (`{}`) body, as well!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Many thanks to both, this was really the issue.
I was mistakenly url encoding the alias both when creating and when closing the Alert.
I just had to stop encoding it in the creation, then things worked like a charm.
EDIT: I wrongly posted this as an answer. Don't know how to delete.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
👏👏👏
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.