Create detectionRule
Namespace: microsoft.graph.security
Important
APIs under the /beta
version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Create a custom detection rule. With custom detections, you can proactively monitor for and respond to various events and system states, including suspected breach activity and misconfigured assets in their organization's network. Custom detection rules, which are written in Kusto query language (KQL), automatically trigger alerts and response actions once there are events matching their KQL queries.
This API is available in the following national cloud deployments.
Global service | US Government L4 | US Government L5 (DOD) | China operated by 21Vianet |
---|---|---|---|
✅ | ❌ | ❌ | ❌ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permission type | Least privileged permissions | Higher privileged permissions |
---|---|---|
Delegated (work or school account) | CustomDetection.ReadWrite.All | Not available. |
Delegated (personal Microsoft account) | Not supported. | Not supported. |
Application | CustomDetection.ReadWrite.All | Not available. |
HTTP request
POST /security/rules/detectionRules
Request headers
Name | Description |
---|---|
Authorization | Bearer {token}. Required. Learn more about authentication and authorization. |
Content-Type | application/json. Required. |
Request body
Within the request body, supply a microsoft.graph.security.detectionRule. Some metadata fields are unnecessary and are ignored, such as 'createdBy' and 'lastModifiedDateTime'.
Response
If successful, this method returns a 201 Created
response code and a microsoft.graph.security.detectionRule object in the response body.
Examples
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/security/rules/detectionRules
Content-Type: application/json
{
"displayName": "Some rule name",
"isEnabled": true,
"queryCondition": {
"queryText": "DeviceProcessEvents | take 1"
},
"schedule": {
"period": "12H"
},
"detectionAction": {
"alertTemplate": {
"title": "Some alert title",
"description": "Some alert description",
"severity": "medium",
"category": "Execution",
"recommendedActions": null,
"mitreTechniques": [],
"impactedAssets": [
{
"@odata.type": "#microsoft.graph.security.impactedDeviceAsset",
"identifier": "deviceId"
}
]
},
"organizationalScope": null,
"responseActions": [
{
"@odata.type": "#microsoft.graph.security.isolateDeviceResponseAction",
"identifier": "deviceId",
"isolationType": "full"
}
]
}
}
Response
The following example shows the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.security.detectionRule",
"id": "35079",
"displayName": "Some rule name",
"isEnabled": true,
"createdBy": "[email protected]",
"createdDateTime": "2023-06-25T09:37:28.6149005Z",
"lastModifiedDateTime": "2023-06-25T09:37:28.6149005Z",
"lastModifiedBy": "[email protected]",
"detectorId": "67aa92a1-b04b-4f2a-a223-236968a3da96",
"queryCondition": {
"queryText": "DeviceProcessEvents | take 1",
"lastModifiedDateTime": null
},
"schedule": {
"period": "12H",
"nextRunDateTime": "2023-06-25T09:37:28.6149005Z"
},
"lastRunDetails": {
"lastRunDateTime": null,
"status": null,
"failureReason": null,
"errorCode": null
},
"detectionAction": {
"alertTemplate": {
"title": "Some alert title",
"description": "Some alert description",
"severity": "medium",
"category": "Execution",
"recommendedActions": null,
"mitreTechniques": [],
"impactedAssets": [
{
"@odata.type": "#microsoft.graph.security.impactedDeviceAsset",
"identifier": "deviceId"
}
]
},
"organizationalScope": null,
"responseActions": [
{
"@odata.type": "#microsoft.graph.security.isolateDeviceResponseAction",
"isolationType": "full",
"identifier": "deviceId"
}
]
}
}