Service Incident Rules API

🚧

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

Create Incident Rule

Create incident rule request is used to add new incident rules for services and it 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.

FieldMandatoryDescriptionLimit
serviceIdtrueId of the service on which incident rule will be created.130 characters
incidentRuletrueRule to be added. For more information about Incident Rule object click here.

Sample Requests

curl -X POST 'https://api.opsgenie.com/v1/services/6980c9d2-45ad-4458-9a72-127b87ef881d/incident-rules'
    -H 'Authorization: GenieKey eb24alp-faa2-4ba2-a551q-1alpf565c889'
    -H 'Content-Type: application/json'
    -d
'{
    "conditionMatchType": "match-all-conditions",
    "conditions": [{
        "expectedValue": "Incident",
        "operation": "contains",
        "not": false,
        "field": "message"
    }],
    "incidentProperties": {
        "message": "Incident Message",
        "description": "Incident Description",
        "tags": ["Tag1", "Tag2"],
        "priority": "P4",
        "stakeholderProperties": {
            "enable": true,
            "message": "Stakeholder Message",
            "description": "Stakeholder Description"
        }
    }
}'

Response:

{
  "data": {
    "id": "b1afd949-f051-48cd-ab67-8cf34f966a57"
  },
  "requestId": "c93ff1c2-e19f-11e7-a9ed-99cc1aa8489f"
}

📘

Please note that a team can have up to 200 incident rules.

Update Incident Rule

Update incident rule request is used to update existing rules on existing services for teams and it 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.

FieldMandatoryDescriptionLimit
serviceIdtrueId of the service on which incident rule will be created.130 characters
incidentRuleIdtrueId of the incident rule to be updated.130 characters
incidentRuletrueRule to be updated.For more information about Incident Rule object click here

Sample Requests

curl -X PUT 'https://api.opsgenie.com/v1/services/6980c9d2-45ad-4458-9a72-127b87ef881d/incident-rules/6980c9d1-45ad-4458-9a72-127b87ef881d'
    -H 'Authorization: GenieKey eb24alp-faa2-4ba2-a551q-1alpf565c889'
    -H 'Content-Type: application/json'
    -d
'{
    "conditionMatchType": "match-any-condition",
    "conditions": [{
        "expectedValue": "Incident",
        "operation": "contains",
        "not": false,
        "field": "message"
    }, {
        "expectedValue": "P1",
        "operation": "equals",
        "not": false,
        "field": "priority"
    }],
    "incidentProperties": {
        "message": "Incident Message - Updated",
        "description": "Incident Description",
        "tags": ["Tag1"],
        "priority": "P5",
        "stakeholderProperties": {
            "enable": true,
            "message": "Stakeholder Message",
            "description": "Stakeholder Description"
        }
    }
}'

Response:

{
  "result": "Updated",
  "data": {
    "id": "6980c9d1-45ad-4458-9a72-127b87ef881d"
  },
  "requestId": "c93ff1c2-e19f-11e7-a9ed-99cc1aa8489f"
}

Delete Incident Rule

Delete incident rule request is used to delete existing rules on existing services for teams and it 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.

FieldMandatoryDescriptionLimit
serviceIdtrueId of the service on which incident rule will be created.130 characters
incidentRuleIdtrueRule id to be deleted.130 characters

Sample Requests

curl -X DELETE 'https://api.opsgenie.com/v1/services/6980c9d2-45ad-4458-9a72-127b87ef881d/incident-rules/123123-1231-121ba'
    -H 'Authorization: GenieKey eb24alp-faa2-4ba2-a551q-1alpf565c889'
    -H 'Content-Type: application/json'

Response:

{
  "result": "Deleted",
  "requestId": "c93ff1c2-e19f-11e7-a9ed-99cc1aa8489f"
}

Get Incident Rules

Get incident rules request is used to retrieve a given service's incident rules

FieldMandatoryDescriptionLimit
serviceIdtrueId of the service from which incident rule will be retrieved.130 characters

Request

curl -X GET 'https://api.opsgenie.com/v1/services/12/incident-rules'
    -H 'Authorization: GenieKey eb24alp-faa2-4ba2-a551q-1alpf565c889'
    -H 'Content-Type: application/json'

Response

{
  "data": [
    {
      "id": "dfa45b69-0ff3-4948-94b0-ec4a33c98d2f",
      "order": 1,
      "conditionMatchType": "match-any-condition",
      "conditions": [
        {
          "field": "message",
          "not": false,
          "expectedValue": "Incident",
          "operation": "contains"
        },
        {
          "field": "priority",
          "not": false,
          "expectedValue": "P1",
          "operation": "equals"
        }
      ],
      "incidentProperties": {
        "message": "Incident Message",
        "tags": [
          "Tag1"
        ],
        "description": "Incident Description",
        "details": {},
        "priority": "P5",
        "stakeholderProperties": {
          "enable": true,
          "message": "Stakeholder Message",
          "description": "Stakeholder Description"
        }
      }
    }
  ],
  "requestId": "c93ff1c2-e19f-11e7-a9ed-99cc1aa8489f"
}

Incident Rule Fields

FieldMandatoryDescriptionLimit
conditionsMandatory if conditionMatchType is not match-allFor more information about conditions object click here.
conditionMatchTypefalseMatch type for given conditions. Possible values are [match-all, match-any-condition, match-all-conditions]. Default value is [match -all].
incidentPropertiestrueFor more information about conditions object click here.

Incident Properties Fields

FieldMandatoryDescriptionLimit
messagetrueMessage of the related incident rule.130 characters
tagsfalseTags of the alert.20 x 50 characters
detailsfalseMap of key-value pairs to use as custom properties of the alert.8000 characters
descriptionfalseDescription field of the incident rule.10000 characters
prioritytruePriority level of the alert. Possible values are P1, P2, P3, P4 and P5
stakeholderPropertiestrueFor more information about conditions object click here.

Stakeholder Properties Fields

FieldMandatoryDescriptionLimit
enablefalseOption to enable stakeholder notifications.Default value is true.
messagetrueMessage that is to be passed to audience that is generally used to provide a content information about the alert.
descriptionfalseDescription that is generally used to provide a detailed information about the alert.15000 characters

Condition Fields

FieldMandatoryDescriptionLimit
fieldtrueSpecifies which alert field will be used in condition. Possible values are message, description, tags, extra-properties, recipients, teams or priority130 characters
notfalseIndicates behaviour of the given operation. Default value is false.512 characters
expectedValuefalseUser defined value that will be compared with alert field according to the operation. Default value is empty string.15000 characters
operationfalseIt 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