Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
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

How can I create a new Policy using the Opsgenie API?

https://docs.opsgenie.com/docs/alert-and-notification-policy-api#create-policy

I am following the API documentation for Sample Request. Essentially a copy + paste and changing out the API key.

curl -X POST 'https://api.opsgenie.com/v2/policies' \
-H "Authorization: GenieKey $ATLASSIAN_API_TOKEN" \
-H 'Content-Type: application/json' \
-d @policy.json

Where policy.json is:

{
"type":"notification",
"policyDescription":"notification policy description ",
"enabled":"true",
"filter":{
"type":"match-all-conditions",
"conditions":[
{
"field":"message",
"operation":"contains",
"expectedValue":"message"
}
]
},
"timeRestrictions":{
"type":"time-of-day",
"restriction":{
"endHour":5,
"endMin":10,
"startHour":20,
"startMin":23
}
},
"name":"Notification with Delay and Restart Actions",
"delayAction":{
"delayOption":"for-duration",
"duration":{
"timeUnit":"seconds",
"timeAmount":5
}
},
"autoRestartAction":{
"duration":{
"timeUnit":"minutes",
"timeAmount":2
},
"maxRepeatCount":5
}
}

The response I get is:

{"message":"Key format is not valid!","took":0.001,"requestId":"fa1fd745-b9e4-4404-869f-2df7ac132939"}%

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.
Oct 17, 2023

Hi @Benjamin Lush ,

Are you using the API key from an Opsgenie API integration, or API key from the API key management tab?

Or are you using an Atlassian token as shown above in your request?

 

For the request above, you will need to use either an API integration's key or an API key from the API key management tab. 

 

You may also want to be consistent with the headers as I noticed one is using single quotes while the other using double quotes.

Looks like this message is regarding the use of an Integration Key. Once I used the Integration Key vs my Personal Access Token, I started getting new errors regarding formatting of Duration and the lack of teamId in Query params. This means the documentation is broken, but at-least I got it to eventually work!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events