Policy API

General Information

🚧

If using the EU instance of Opsgenie, the URL needs to be https://api.eu.opsgenie.com for requests to be successful.

πŸ“˜

Create an API Integration and obtain your apiKey to make requests listed below. Please make sure that the integration is not restricted to access configurations.

Create Policy

Create policy request is a write request. If the integration of the API key configured as read-only, the request will not be accepted. For more information, you can refer to API Access Management.

Common JSON Body Fields

FieldsMandatoryDescriptionLimit
typetrueType of the policy. Should be one of alert and notification
nametrueName of the policy100 chars
enabledtrueInitial status of the integration.
policyDescriptionfalseDescription of the policy200 chars
filterfalseConditions specified in this field must be met for this policy to work. You can refer to Filter for detailed information about filter and its fields
timeRestrictionsfalseTime restrictions specified in this field must be met for this policy to work. You can refer to Time constraints and time zones for detailed information about time restriction and its fields

Query Parameters

ParameterMandatoryDescription
teamId*falseThe identifier of the team that this policy belongs. Value should be null for global policies.

πŸ“˜

You can make api requests with global integrations, for global and team-based policies. teamId parameter should be null for global policies. Can be any team id for global integrations.
You can make api requests with team-based integrations, for team-based policies only. teamId parameter cannot be null and should be the same with the integration's teamId.

Extra Fields for Alert Policy

ParameterMandatoryDescription
messagetrueMessage of the alert
continuefalseWill trigger other modify policies if set to true. Default value is false
aliasfalseAlias of the alert. You can use {{alias}} to refer to the original alias. Default value is {{alias}}
descriptionfalseDescription of the alert. You can use {{description}} to refer to the original alert description. Default value is {{description}}
entityfalseEntity field of the alert. You can use {{entity}} to refer to the original entity. Default value is {{entity}}
sourcefalseSource field of the alert. You can use {{source}} to refer to the original source. Default value is {{source}}
ignoreOriginalActionsfalseIf set to true, policy will ignore the original actions of the alert. Default value is false
actionsfalseActions as a list of strings to add to the alerts original actions value. If ignoreOriginalActions field is set to true, this will replace the original actions.
ignoreOriginalDetailsfalseIf set to true, policy will ignore the original details of the alert. Default value is false
detailsfalseMap of key-value pairs to use as custom properties of the alert details. If ignoreOriginalDetails field is set to true, this will replace the original details.
ignoreOriginalRespondersfalseIf set to true, policy will ignore the original responders of the alert. Default value is false
respondersfalseResponders to add to the alerts original responders value as a list of teams, users or the reserved word none or all. If ignoreOriginalResponders field is set to true, this will replace the original responders. The possible values for responders are:
user
team

You can refer below for example values
ignoreOriginalTagsfalseIf set to true, policy will ignore the original tags of the alert. Default value is false
tagsfalseTags to add to the alerts original tags value as a list of strings. If ignoreOriginalResponders field is set to true, this will replace the original responders.
priorityfalsePriority of the alert. Should be one of P1, P2, P3, P4, or P5

πŸ“˜

You can use string operations with alias, description, entity and source fields. For more detailed instructions, you can refer to string processing methods

Responders field example:

{
    "responders": [
        {
            "type": "team",
            "id": "0f5f6b40-7dca-44fc-8036-6d6d550e853f"
        },
        {
            "type": "user",
            "id": "dde5a8e0-5b8d-4270-9e94-b1bd8ba7a63b"
        }
    ]
}

Sample Requests

curl -X POST  'https://api.opsgenie.com/v2/policies'
    --header 'Authorization: GenieKey sdy4brs-faa2-4ba2-a551q-1brsf565c889'
    --header 'Content-Type: application/json'
    --data
'{
    "type":"alert",
    "policyDescription":"alert policy description ",
    "enabled":"true",
    "filter":{
        "type":"match-all-conditions",
        "conditions":[
            {
                "field":"message",
                "operation":"contains",
                "expectedValue":"dynamodb"
            }
        ]
    },
    "timeRestrictions":{
       "type":"weekday-and-time-of-day",
       "restrictions":[{
      		 "startDay":"monday",
       		 "endDay":"thursday",
			 "endHour":5,
			 "endMin":10,
			 "startHour":20,
		 	 "startMin":23	
       }]
    },
    "ignoreOriginalResponders": true,
    "ignoreOriginalTags": true,
    "continue": true,
    "name":"Alert Policy",
    "message":"{{message}} db error",
    "responders":[{"type":"user","id":"1e1d2ba1-4532-4602-878e-9db1aa927164"}],
    "alias":"{{alias.toLowerCase()}} dynamodb",
    "tags":["dynamodb"],
    "description":"{{description}}"
}'

Response:

{
    "data": {
        "id": "f3006e61-8b35-4f63-8272-9589622474bb",
        "name": "Alert Policy",
        "type": "alert",
        "enabled": true
    },
    "took": 0.142,
    "requestId": "0f5f6b40-7dca-44fc-8036-6d6d550e853f"
}

Extra Fields for Notification Policy

ParameterMandatoryDescription
autoRestartActionfalseAuto Restart Action of the policy. You can refer You can refer here for details.
autoCloseActionfalseAuto Close Action of the policy. You can refer here for details.
deduplicationActionfalseDeduplication Action of the policy. You can refer here for details.
delayActionfalseDelay Action of the policy. You can refer here for details.
suppressfalseSuppress value of the policy. Default value is false.

Sample Requests

curl -X POST  'https://api.opsgenie.com/v2/policies'
    --header 'Authorization: GenieKey sdy4brs-faa2-4ba2-a551q-1brsf565c889'
    --header 'Content-Type: application/json'
    --data
'{
    "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
    }
}'

Response:

{
    "data": {
        "id": "f67c9562-4251-4b92-b0e7-147f3a2d28e2",
        "name": "Notification with Delay and Restart Actions",
        "type": "notification",
        "enabled": true
    },
    "took": 0.129,
    "requestId": "dde5a8e0-5b8d-4270-9e94-b1bd8ba7a63b"
}

Get Policy

In-Line Parameters

Referred NameDescription
identifierId of the policy

Query Parameters

ParameterMandatoryDescription
teamIdfalseThe identifier of the team that this policy belongs. Value should be null for global policies.

Sample Request for Global Policy

curl -X GET  'https://api.opsgenie.com/v2/policies/2b228902-cc04-4f8a-b64f-a381f1289c9b'
    --header 'Authorization: GenieKey sdy4brs-faa2-4ba2-a551q-1brsf565c889'

Sample Request for Team Policy

curl -X GET  'https://api.opsgenie.com/v2/policies/2b228902-cc04-4f8a-b64f-a381f1289c9b?teamId=03b70a5b-3be4-43c1-a2b5-4d2f7e6b6ae8'
    --header 'Authorization: GenieKey sdy4brs-faa2-4ba2-a551q-1brsf565c889'

Response:

{
    "data": {
        "type": "notification",
        "name": "notification delayUntil",
        "enabled": true,
        "policyDescription": "",
        "id": "36b6f2e3-8f99-4a68-8f8f-a877873718d1",
        "filter": {
            "type": "match-all-conditions",
            "conditions": [
                {
                    "field": "message",
                    "not": false,
                    "operation": "contains",
                    "expectedValue": "message",
                    "order": 0
                },
                {
                    "field": "responders",
                    "not": true,
                    "operation": "contains",
                    "expectedValue": "recipient",
                    "order": 0
                }
            ]
        },
        "timeRestrictions": {
            "type": "time-of-day",
            "restriction": {
                "startHour": 20,
                "endHour": 5,
                "startMin": 23,
                "endMin": 10
            }
        },
        "delayAction": {
            "delayOption": "next-time",
            "duration": null,
            "untilHour": 1,
            "untilMinute": 5
        },
        "suppress": false
    },
    "took": 0.211,
    "requestId": "5120e157-ea9c-4865-8ab0-0ed8ed7a0955"
}

Update Policy

Update policy request is a write request. If the integration of the API key configured as read-only, the request will not be accepted. For more information, you can refer to API Access Management.

πŸ“˜

This is a full update so it uses the same body fields and same query parameters with create requests.

In-Line Parameters

Referred NameDescription
identifierIdentifier of the policy

Query Parameters

ParameterMandatoryDescription
teamIdfalseThe identifier of the team that this policy belongs. Value should be null for global policies.

Sample Request for Global Policy

curl -X PUT 'https://api.opsgenie.com/v2/policies/c059164d-92dc-4a96-8caa-e70840a545a8'
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889'
    --header 'Content-Type: application/json'
    --data
'{
    "type":"notification",
    "policyDescription":"updated description",
    "enabled":"true",
    "filter":{
        "type":"match-all-conditions",
        "conditions":[
            {
                "field":"responders",
                "operation":"contains",
                "expectedValue":"recipient",
                "not":true
            },
            {
                "field":"message",
                "operation":"contains",
                "expectedValue":"message"
            }
        ]
    },
    "name":"notification suppress",
    "suppress":true
}'

Response

{
    "result": "Updated",
    "took": 0.194,
    "requestId": "00bf03f6-ac9a-472c-91b2-80ca177b6471"
}

Delete Policy

Delete policy request is a write request. If the integration of the API key configured as read-only, the request will not be accepted. For more information, you can refer to API Access Management.

In-Line Parameters

Referred NameDescription
identifierId of the policy

Query Parameters

ParameterMandatoryDescription
teamIdfalseThe identifier of the team that this policy belongs. Value should be null for global policies.

Sample Request for Global Policy

curl -X DELETE 'https://api.opsgenie.com/v2/policies/53352b69-1ede-42c6-a0fe-73291019f18e'
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889'

Sample Request for Team Policy

curl -X DELETE 'https://api.opsgenie.com/v2/policies/53352b69-1ede-42c6-a0fe-73291019f18e?teamId=03b70a5b-3be4-43c1-a2b5-4d2f7e6b6ae8
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889'

Response:

{
    "result": "Deleted",
    "took": 0.254,
    "requestId": "a3886a19-ec77-468f-ae53-628f9e5909f2"
}

Disable Policy

Disable policy request is a write request. If the integration of the API key configured as read-only, the request will not be accepted. For more information, you can refer to API Access Management.

In-Line Parameters

Referred NameDescription
identifierId of the policy

Query Parameters

ParameterMandatoryDescription
teamIdfalseThe identifier of the team that this policy belongs. Value should be null for global policies.

Sample Request for Global Policy

curl -X POST 'https://api.opsgenie.com/v2/policies/2b228902-cc04-4f8a-b64f-a381f1289c9b/disable'
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889'

Sample Request for Team Policy

curl -X POST 'https://api.opsgenie.com/v2/policies/2b228902-cc04-4f8a-b64f-a381f1289c9b/disable?teamId=03b70a5b-3be4-43c1-a2b5-4d2f7e6b6ae8'
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889'

Response:

{
    "result": "Disabled",
    "took": 0.031,
    "requestId": "3ef3e18e-f324-4a45-a31c-3b201d36aa2c"
}

Enable Policy

Enable policy request is a write request. If the integration of the API key configured as read-only, the request will not be accepted. For more information, you can refer to API Access Management.

In-Line Parameters

Referred NameDescription
identifierId of the policy

Query Parameters

ParameterMandatoryDescription
teamIdfalseThe identifier of the team that this policy belongs. Value should be null for global policies.

Sample Request for Global Policy

curl -X POST 'https://api.opsgenie.com/v2/policies/2b228902-cc04-4f8a-b64f-a381f1289c9b/enable'
    --header 'Authorization: GenieKey eb243592-faa2-4ba2-a551q-1brsf565c889'

Response:

{
    "result": "Enabled",
    "took": 0.034,
    "requestId": "89745648-19de-49da-a563-adb2243c212f"
}

Change Policy Order

Change order request is a write request. If the integration of the API key configured as read-only, the request will not be accepted. For more information, you can refer to API Access Management.

In-Line Parameters

Referred NameDescription
identifierId of the policy

Query Parameters

ParameterMandatoryDescription
teamIdfalseThe identifier of the team that this policy belongs. Value should be null for global policies.

JSON Body Fields

FieldsMandatoryDescription
targetIndextrueOrder of the target policy will be changed to this value. Larger values than policy count will put the target policy to last slot. Should be at least 0

Sample Request for Global Policy

curl -X POST 'https://api.opsgenie.com/v2/policies/2b228902-cc04-4f8a-b64f-a381f1289c9b/change-order'
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889
    --header 'Content-Type: application/json'
    --data
'{
    "targetIndex":5
}';

Sample Request for Team Policy

curl -X POST 'https://api.opsgenie.com/v2/policies/2b228902-cc04-4f8a-b64f-a381f1289c9b/change-order?teamId=03b70a5b-3be4-43c1-a2b5-4d2f7e6b6ae8'
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889
    --header 'Content-Type: application/json'
    --data
'{
    "targetIndex":5
}';

Response

{
    "result": "Order Changed",
    "took": 0.134,
    "requestId": "89745568-12ge-41aa-a8fe-abd224c3212f"
}

List Alert Policies

Used to get global and team-based alert policies.

πŸ“˜

This API Call only allows a limit of 1000 results

Query Parameters

ParameterMandatoryDescription
teamIdfalseThe identifier of the team for listing team-based alert policies. Should be null for global policies.

Sample Request for Global Policies

curl -X GET 'https://api.opsgenie.com/v2/policies/alert'
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889'

Sample Request for Team Alert Policies

curl -X GET 'https://api.opsgenie.com/v2/policies/alert?teamId=03b70a5b-3be4-43c1-a2b5-4d2f7e6b6ae8'
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889'

Response:

{
    "data": [
        {
            "id": "a697b628-e0e3-4043-b01f-6b587e5e98a0",
            "name": "Alert Policy",
            "type": "alert",
            "order": 0,
            "enabled": true
        },
        {
            "id": "2b228902-cc04-4f8a-b64f-a381f1289c9b",
            "name": "Alert Policy 2",
            "type": "alert",
            "order": 1,
            "enabled": true
        },
        {
            "id": "bcf68e62-bf5f-4483-8e57-554e4881420f",
            "name": "Alert Policy 3",
            "type": "alert",
            "order": 2,
            "enabled": true
        },
    ],
    "took": 0.2,
    "requestId": "bbe30c0b-c6e5-4102-92f1-d7dd8b645124"
}

List Notification Policies

Used to list team notification policies.

Query Parameters

ParameterMandatoryDescription
teamIdtrueThe identifier of the team for listing team-based notification policies.

Sample Request

curl -X GET 'https://api.opsgenie.com/v2/policies/notification?teamId=03b70a5b-3be4-43c1-a2b5-4d2f7e6b6ae8'
    --header 'Authorization: GenieKey sdy43592-faa2-4ba2-a551q-1brsf565c889'

Response:

{
    "data": [
        {
            "id": "a697b628-e0e3-4043-b01f-6b587e5e98a0",
            "name": "Notification Policy with Delay Action",
            "type": "notification",
            "order": 0,
            "enabled": true
        },
        {
            "id": "2b228902-cc04-4f8a-b64f-a381f1289c9b",
            "name": "Notification Policy with Suppress",
            "type": "notification",
            "order": 1,
            "enabled": true
        },
        {
            "id": "bcf68e62-bf5f-4483-8e57-554e4881420f",
            "name": "Notification Policy with Delay and AutoRestart",
            "type": "notification",
            "order": 2,
            "enabled": true
        },
    ],
    "took": 0.009,
    "requestId": "bbe30c0b-c6e5-4102-92f1-d7dd8b645124"
}

Delay Action Fields

FieldMandatoryDescription
delayOptiontrueDelay type. Should be one of for-duration, next-time, next-weekday, next-monday, next-tuesday, next-wednesday, next-thursday, next-friday, next-saturday, next-sunday
untilMinutetrue*Minute field of the Should be a number between 0-59
untilHourtrue*Should be a number between 0-23
durationfalse*Delay duration. You can refer here for details

🚧

If delayOption is for-duration, untilHour and untilMinute is redundant and duration is mandatory

Deduplication Action Fields

FieldMandatoryDescription
deduplicationActionTypetrueDeduplication type. Should be one of value-based or frequency-based
counttrueNumber of alerts before deduplication
durationfalseInterval to keep count of alerts for frequency based deduplication. You can refer here for details

Auto Restart Action Fields

FieldMandatoryDescription
durationtrueDuration to wait until restarting the alert flow. You can refer here for details
maxRepeatCounttrueMaximum count to restart notification flow

Auto Close Action Fields

FieldMandatoryDescription
durationtrueDuration to wait until closing the alert. You can refer here for details

Time Restriction Fields

Used to limit policies to certain day and time of the week, using multiple start and end times for each day of the week. This allows applying different policies at different times.

Day Based Restriction

If the time restrictions will be configured as day based, this parameter should be used. timeRestriction parameter for daily restrictions should have the following format:

FieldMandatoryDescription
typetrueThis parameter should be set time-of-day
restrictiontrueIt is a restriction object which is described below. In this case startDay/endDay fields are not supported

Fields of Restriction Object

FieldMandatoryDescription
startHourtrueValue of the hour that frame will start
startMintrueValue of the minute that frame will start
endHourtrueValue of the hour that frame will end
endMintrueValue of the minute that frame will end

restriction field example:

{
    "timeRestriction": {
        "type" : "time-of-day",
        "restriction" :
        {
            "startHour" : 8,
            "startMin" : 0,
            "endHour" : 18,
            "endMin" : 30
        }
    }
}

Week Based Restrictions

If the time restrictions will be configured as week based, this parameter should be used. timeRestriction parameter for weekly restrictions should have the following format:

FieldMandatoryDescription
typetrueThis parameter should be set weekday-and-time-of-day
restrictionstrueIt is a list of restriction objects which are described below

Fields of Restrictions Object

startDaytrueName of day which time frame will start. May be one of monday, tuesday, wednesday, thursday, friday, saturday, sunday. Only used if type of restrictions is given weekday-and-time-of-day
startHourtrueValue of the hour that frame will start
startMintrueValue of the minute that frame will start
endDaytrueName of day which time frame will end. May be one of monday, tuesday, wednesday, thursday, friday, saturday, sunday. Only used if type of restrictions is given weekday-and-time-of-day
endHourtrueValue of the hour that frame will end
endMintrueValue of the minute that frame will end

restrictions field example:

{
    "timeRestriction": {
        "type" : "weekday-and-time-of-day",
        "restrictions" : [
            {
                "startDay" : "monday",
                "startHour" : 8,
                "startMin" : 0,
                "endDay" : "tuesday",
                "endHour" : 18,
                "endMin" : 30
            },
            {
                "startDay" : "wednesday",
                "startHour" : 8,
                "startMin" : 0,
                "endDay" : "thursday",
                "endHour" : 18,
                "endMin" : 30
            }
        ]
    }
}

Filter Fields

Defines the conditions that will be checked before applying policies and type of the operations that will be applied on these conditions

JSON Body Fields

FieldsMandatoryDescription
typetrueType of the operation will be applied on conditions. Should be one of match-all, match-any-condition or match-all-conditions
conditionstrue *List of conditions will be checked before applying policy

🚧

If operation type is match-all, conditions field is not necessary/mandatory.

Fields of Conditions Object

FieldMandatoryDescription
fieldtrueSpecifies which alert field will be used in condition. Possible values are message, alias, description, source, entity, tags, actions, details, extra-properties, responders, teams or priority
keyfalseIf field is set as extra-properties, key could be used for key-value pair
notfalseIndicates behaviour of the given operation. Default value is false
operationtrueIt is the operation that will be executed for the given field and key. Possible operations are matches, contains, starts-with, ends-with, equals, contains-key, contains-value, greater-than, less-than, is-empty and equals-ignore-whitespace. Available operations changes according to the fields type:


String Operations: contains, equals, starts-with, ends-with, matches, is-empty, equals-ignore-whitespace
List Operations: contains, is-empty
Map Operations:contains, contains-key, contains-value, is-empty
Number Operations: matches, equals, greater-than, less-than
* Boolean Operations: equals
expectedValuefalseUser defined value that will be compared with alert field according to the operation. Default value is empty string
orderfalseOrder of the condition in conditions list

filter field example:

{
    "filter": {
        "type": "match-all"
    }
}
{
    "filter": {
        "type": "match-any-condition",
        "conditions": [
            {
                "field": "message",
                "not": false,
                "operation": "contains",
                "expectedValue": "expected1"
            },
            {
                "field": "alias",
                "not": true,
                "operation": "starts-with",
                "expectedValue": "expected2"
            },
            {
                "field": "extra-properties",
                "key": "expectedKey",
                "not": true,
                "operation": "starts-with",
                "expectedValue": "expected3"
            }
        ]
    }
}

Duration Fields

Duration to wait until taking an action in time based policies

JSON Body Fields

FieldsMandatoryDescription
timeUnitfalseTime unit used in duration. Should be one of days, hours or minutes
Default value is minutes
timeAmounttrueAmount of time

duration field example:

"duration":{
    "timeAmount":10,
    "timeUnit":"minutes"
}
"duration":{
    "timeAmount":5,
    "timeUnit":"days"
}