# Create alert

## **Create Alert**

Create Alert endpoint allows our customers to create alerts that are triggered when one of Genlogs sensors detect a truck that match the alert criteria, sending an email with the detection results.

This endpoint is restricted to authorized users with appropriate permissions.

### Authentication

Include the following headers in your requests:

* **Access-Token**: The access token obtained from the "Create Access Token" endpoint.
* **x-api-key**: The API key provided by GenLogs. This header must be included in the request.

### Permissions

Make sure that your api user is created with a role that has `admin` or `create-alert-endpoint`  permission

### Endpoint

* **URL**: `https://api.genlogs.io/alerts`
* **Method**: `POST`

### Request Format

All parameters must be sent as JSON in the request body with `Content-Type: application/json` header.

### Request Parameters

* **email** (string, Required): The email address to the alert results if a match is found
* **cc\_emails** (array of strings, Optional): List of additional email addresses to receive notifications  if a match is found based on alerts criteria
* **alert\_type** (string, Required): Specifies the type of alert to be sent.
  * **normal**: Also called "Daily Alerts", these are triggered once per day in the morning.
  * **hot**: Triggered every 15 minutes.
* **disabled** (boolean, Required): Whether the alert is active or disabled.
* **alert\_name** (string, Required): The name of the alert for identification.
* **usdot\_number** (string, Optional): The USDOT number for alert identification.
* **mc\_number** (string, Optional): The MC number for alert identification.
* **license\_plate** (string, Optional): The license plate number related to the alert.
* **vin** (string, Optional):  Last 6 Digits of the vehicle identification number.
* **cab\_number** (string, Optional): The cab number associated with the vehicle.
* **equipment\_type** (string, Optional): The equipment type for alert identification.
* **trailer\_logo** (string, Optional): The logo displayed on the trailer.
  * The logo displayed on the trailer. See [trailer-logos](https://docs.genlogs.io/alerts/create-alert/trailer-logos "mention") for options.
* **trailer\_number** (string, Optional): The trailer number associated with the alert.
* **exact\_match\_trailer\_number** (boolean, Optional): Specifies whether the trailer number search should match exactly or be treated as a “contains” search.
  * **true**: Performs an exact match for the trailer number.
  * **false**: Utilizes a “contains” search for the trailer number.
* **deep\_search** (string, Optional): The deep search criteria associated to the alert
* **exact\_match\_deep\_search** (boolean, Optional): Specifies whether the deep search criteria should match exactly or be treated as a “contains” search.
  * **true**: Performs an exact match for the deep search criteria.
  * **false**: Utilizes a “contains” search for the deep search criteria.
* **notification\_channels** (array of strings, Optional): list of channels to receive notifications `"email"`, `"webhook"`. **Default**: `["email"]` if not specified.

### Response Codes

* **200 OK**: Successfully created the alert.
* **400 Bad Request**: Missing or invalid parameters.
* **401 Unauthorized**: Authentication credentials are missing or incorrect.
* **403 Forbidden**: The user does not have permission to create alerts.
* **500 Internal Server Error**: An issue occurred on the server.

### Response Body:

{% hint style="info" %}
You must save the alert ID in order to use the `Edit Alert` endpoint.
{% endhint %}

* **id** (integer): Unique identifier for the alert.
* **email** (string): The email address associated with the alert.
* **cc\_emails** (array of strings): List of additional email addresses for notifications.
* **alert\_name** (string): The name of the alert.
* **usdot\_number** (string): The USDOT number associated to the alert.
* **mc\_number** (string): The MC number associated to the alert.
* **disabled** (boolean): Indicates whether the alert is active or disabled.
* **alert\_type** (string): Type of alert (`normal`or `hot`)
* **location\_state** (string, nullable): State where the alert is triggered.
* **location\_city** (string, nullable): City where the alert is triggered.
* **license\_plate** (string, nullable): License plate involved in the alert.
* **vin** (string, nullable): Vehicle Identification Number.
* **cab\_number** (string, nullable): Cab number.
* **equipment\_type** (string, nullable): Equipment type.
* **trailer\_logo** (string, nullable): Logo on the trailer.
* **trailer\_number** (string, nullable): Trailer number.
* **exact\_match\_trailer\_number** (boolean): Indicates if the trailer number must match exactly.
* **deep\_search** (string, nullable): Deep search criteria.
* **exact\_match\_deep\_search** (boolean)**:** Indicates if the Deep search criteria must match exactly.
* **notification\_channels** (array of strings): Indicates list of channels to receive notifications

### Request Example

Using `curl`:

```
curl -X POST 'https://api.genlogs.io/alerts' \
-H 'Access-Token: {access_token}' \
-H 'x-api-key: {your_api_key}' \
-H 'Content-Type: application/json' \
-d '{
  "email": "user@example.com",
  "cc_emails": "notification@example.com",
  "alert_type": "normal",
  "disabled": false,
  "alert_name": "New alert",
  "trailer_number": "12345",
  "usdot_number": "",
  "deep_search": "",
  "exact_match_deep_search": false
}'
```

This API ensures secure alert creation while maintaining proper role-based access control.
