Opsgenie API - close alert based on alias not working
Asked by Luis Helder:

I'm trying to close an alert using the API based on its alias.  

The alert looks like this:  

![screenshot.png](/t5/image/serverpage/image-id/196918iE20EECFF297FA3D3/image-size/large?v=v2&px=999 "screenshot.png")  

<br />

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.


Answers:
author: Tom Russell
body: [@Luis Helder](/t5/user/viewprofilepage/user-id/4922060) , 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"


author: Nick H
body: Hi [@Luis Helder](/t5/user/viewprofilepage/user-id/4922060) ,

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](https://docs.opsgenie.com/docs/alert-api#close-alert), 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:

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

As a side note, you will want to send the POST request with an empty (\`{}\`) body, as well!


author: Luis Helder
body: 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.

comments: author: Nick H
body: ???


Tags: cloud