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.
HTTP Method | URL |
---|---|
POST | https://api.opsgenie.com/v1/services/:serviceId/incident-rules |
Field | Mandatory | Description | Limit |
---|---|---|---|
serviceId | true | Id of the service on which incident rule will be created. | 130 characters |
incidentRule | true | Rule 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 remind that team can contain up to 100 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.
Field | Mandatory | Description | Limit |
---|---|---|---|
serviceId | true | Id of the service on which incident rule will be created. | 130 characters |
incidentRuleId | true | Id of the incident rule to be updated. | 130 characters |
incidentRule | true | Rule 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.
HTTP Method | URL |
---|---|
DELETE | https://api.opsgenie.com/v1/services/:serviceId/incident-rules/:incidentRuleId |
Field | Mandatory | Description | Limit |
---|---|---|---|
serviceId | true | Id of the service on which incident rule will be created. | 130 characters |
incidentRuleId | true | Rule 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
HTTP Method | URL |
---|---|
GET | https://api.opsgenie.com/v1/services/:serviceId/incident-rules |
Field | Mandatory | Description | Limit |
---|---|---|---|
serviceId | true | Id 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
Field | Mandatory | Description | Limit |
---|---|---|---|
conditions | Mandatory if conditionMatchType is not match-all | For more information about conditions object click here. | |
conditionMatchType | false | Match type for given conditions. Possible values are [match-all, match-any-condition, match-all-conditions]. Default value is [match -all]. | |
incidentProperties | true | For more information about conditions object click here. |
Incident Properties Fields
Field | Mandatory | Description | Limit |
---|---|---|---|
message | true | Message of the related incident rule. | 130 characters |
tags | false | Tags of the alert. | 20 x 50 characters |
details | false | Map of key-value pairs to use as custom properties of the alert. | 8000 characters |
description | false | Description field of the incident rule. | 10000 characters |
priority | true | Priority level of the alert. Possible values are P1, P2, P3, P4 and P5 | |
stakeholderProperties | true | For more information about conditions object click here. |
Stakeholder Properties Fields
Field | Mandatory | Description | Limit |
---|---|---|---|
enable | false | Option to enable stakeholder notifications.Default value is true. | |
message | true | Message that is to be passed to audience that is generally used to provide a content information about the alert. | |
description | false | Description that is generally used to provide a detailed information about the alert. | 15000 characters |
Condition Fields
Field | Mandatory | Description | Limit |
---|---|---|---|
field | true | Specifies which alert field will be used in condition. Possible values are message, description, tags, extra-properties, recipients, teams or priority | 130 characters |
not | false | Indicates behaviour of the given operation. Default value is false. | 512 characters |
expectedValue | false | User defined value that will be compared with alert field according to the operation. Default value is empty string. | 15000 characters |
operation | false | It 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:
|
Updated 6 months ago