## 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 Body Content

- **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 [List logos](https://docs.genlogs.io/alerts/list-logos) endpoint.

- **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:

You must save the alert ID in order to use the `Edit Alert` endpoint.

- **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.
