Create a Trigger for Anomaly Detection
# Create a Trigger for Anomaly Detection ### `POST /v2/triggers` Creating a trigger for anomaly detection is similar to creating any trigger in Connectivity Management. The only difference is a few new values added for Anomaly Detection. This page will cover the new values and provide examples of what requests look like with the new values. The API Reference page for creating a trigger can be found at [Create a Trigger for Usage Notifications](https://thingspace.verizon.com/documentation/api-documentation.html#/http/connectivity-management/guides/uses-and-requirements/create-a-trigger-for-usage-notifications). ## HTTP Request POST [https://thingspace.verizon.com/api/m2m/v2/triggers](/docs/premium-apis/thingspace-intelligence/api-endpoints/anomaly-triggers-v2/createanomalydetectiontriggerv2) ## Request Body | Parameter Name | Data Type | Description | |:-----------------------------------------------------------------------------------|:---------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | **triggerCategory** <br> *(required)* | string | `UsageAnomaly` - This is the value to use in the request body to detect anomalous behaivior. The values in this table will only be relevant when this parameter is set to this value. | | **anomalyTriggerRequest** | object | The details of the `UsageAnomaly` trigger. | | **anomalyTriggerRequest.accountNames** <br> *(either `accountNames` or `deviceGroup` is required)* | string | The Verizon billing accounts associated with the anomaly triggers for this trigger to be active for devices in those accounts. An account name is usually numeric, and must include any leading zeros. | | **anomalyTriggerRequest.deviceGroups** <br> *(either `accountNames` or `deviceGroup` is required)* | string | The names of device groups associated with the anomaly triggers for this trigger to be active for devices in those groups. | | **anomalyTriggerRequest.includeAbnormal** <br>*(required)* | boolean | Whether or not to include anomalies classified as “abnormal". `true` or `false`. <br> Classification is set as part of ThingSpace Intelligence anomaly detection settings. | | **anomalyTriggerRequest.includeVeryAbnormal** <br> *(required)* | boolean | Whether or not to include anomalies classified as “very abnormal”. `true` or `false`. <br> Classification is set as part of ThingSpace Intelligence anomaly detection settings. | | **anomalyTriggerRequest.includeUnderExpectedUsage** <br> *(required)* | boolean | Whether or not to include anomalies that are directionally under the expected usage. `true` or `false`. | | **anomalyTriggerRequest.includeOverExpectedUsage** <br> *(required)* | boolean | Whether or not to include anomalies that are directionally over the expected usage. `true` or `false`. | | **notification** <br> *(required)* | object | The notification details of the trigger. | | **notification.notificationType** <br> *(required)* | string | The type of notification, i.e. "DailySummary". | | **notification.callback** <br> *(required)* | boolean | Whether or not the notification should be sent via callback. `true` or `false`. | | **notification.emailNotification** <br> *(required)* | boolean | Whether or not the notification should be sent via e-mail. `true` or `false`. | | **notification.externalEmailRecipients** <br> *(required when emailNotification = true)* | string | E-mail address(es) where the notification should be delivered. | | **notification.notificationGroupName** | string | Name for the notification group | | **notification.severity** | string | Severity level associated with the notification. Examples would be: `Major`, `Minor`, `Critical`, `NotApplicable`. | | **active** | boolean | Indicates Anomaly Detection is active. `True` - Anomaly Detection is active, `False` - Anomaly Detection is not active. | | **active** | boolean | Indicates if the trigger is active. `True` - trigger is active, `False` - trigger is not active. | ### Example Request Example of a trigger created at an account level: ``` json { "name":"Anomaly Daily Usage REST Test-Patch 1", "triggerCategory":"UsageAnomaly", "accountName":"0000123456-00001", "anomalyTriggerRequest":{ "accountNames":["0000123456-00001"], "includeAbnormal":true, "includeVeryAbnormal":true, "includeUnderExpectedUsage":true, "includeOverExpectedUsage":true }, "notification":{ "notificationType":"DailySummary", "callback":true, "emailNotification":false, "notificationGroupName":"Anomaly Test API", "notificationFrequencyFactor":3, "notificationFrequencyInterval":"20", "externalEmailRecipients":"placeholder@verizon.com", "smsNotification":true, "smsNumbers":"12345", "reminder":true, "severity":"Critical" }, "active":true } ``` ## Success Responses ``` json { "triggerId": "595f5c44-c31c-4552-8670-020a1545a84d", } ``` ## Failure Responses All error messages are returned in this format: ``` json { "errorCode": "error code string", "errorMessage": "error message string" } ``` ## Callback Examples These endpoints send responses asynchronously. In order to read the results a callback is required. To learn more about callbacks, please visit [About Callback Services](https://thingspace.verizon.com/documentation/api-documentation.html#/http/connectivity-management/guides/working-with-verizon-wireless/about-callback-services). Example of a callback for a daily summary of anomaly alerts: ``` json { "username":"rv", "password":"123", "requestId":"824b1321-fc93-4864-a559-68ffebeba0bb", "deviceResponse":{ "alertServiceResponse":{ "triggerId":"595f5c44-c31c-4552-8670-020a1545a84d", "triggerName":"Rule Anomaly Daily Summary21Oct_18", "triggerDateTime":"10/26/2021 4:27:37 AM", "message":"Usage Anomaly Alert : Daily Summary for Account Number 0000123456-00001 on 10/26/2021 ", "accountName":"0000123456-00001", "anomaly":{ "anomalyDevicesCount":3, "abnormalEventsCount":5, "veryAbnormalEventsCount":0 }, "notificationType":"Daily Summary" } }, "callbackCount":1, "maxCallbackThreshold":4 } ```