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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,458,594
Community Members
 
Community Events
176
Community Groups

Opsgenie API - close alert based on alias not working

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

The alert looks like this:

screenshot.png


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.

3 answers

2 accepted

3 votes
Answer accepted

@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"

1 vote
Answer accepted

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:

url1.jpg

 

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

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.

Nick H Atlassian Team May 11, 2022

👏👏👏

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS

Atlassian Community Events