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

Benjamin Lush October 17, 2023

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 Haller
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 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.

1 vote
Benjamin Lush October 17, 2023

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