> For the complete documentation index, see [llms.txt](https://docs.genlogs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.genlogs.io/alerts/mismatch-alerts/create-mismatch-alerts.md).

# Create Mismatch Alerts

Creates trailer mismatch observation alerts for the authenticated customer from standalone USDOT numbers, standalone MC numbers, and paired MC/USDOT records. Endpoint: `POST /mismatch-observations`.

### **Authentication**

* Include your **`Access-Token`** and **`x-api-key`** in the header of your requests.

### Permissions

The `external-api-mismatch-observations` permission is required to access this endpoint.

### **Endpoint**

* **URL:** `https://api.genlogs.io/mismatch-observations`
* **Method:** `POST`

### **Headers**

* **Access-Token** (string, required): Access token obtained from the "Create Access Token" endpoint.
* **x-api-key** (string, required): The API key provided by GenLogs.
* **Content-Type** (string, required): `application/json`. Without it the request is rejected with a 400.

### Request body:

At least one of `usdots`, `mcs`, or `pairs` must contain a value. Any property not listed here is rejected with a 400.

* `usdots` (array of strings, optional): Standalone USDOT numbers. Each one creates one mismatch alert.
* `mcs` (array of strings, optional): Standalone MC numbers. Each one creates one mismatch alert.
* `pairs` (array of objects, optional): Paired MC/USDOT records. Each object creates one combined mismatch alert with both values. Both `mc` and `usdot` are required in each object.

```json
{ "mc": "7894", "usdot": "9637" }
```

* `alert_name` (string, optional): Name of the alert(s) for your reference. Omitted or blank names are stored as `null`.
* `logos` (array of strings, optional): Trailer logos to watch, up to 20. Each value must be one of the values returned by the List logos endpoint. Values are case-insensitive and stored in lowercase.

### How alerts are counted

* One alert is created for each USDOT in `usdots`, each MC in `mcs`, and each object in `pairs`.
* USDOT and MC values must be numeric. Leading zeros are removed. A non-numeric value rejects the whole request with a 400.
* Empty values are skipped and not counted.
* Repeated values in the same request are created only once.
* Values are not compared with alerts you already have, so sending the same request twice creates the alerts twice.

### Request Example:

```bash
curl --location 'https://api.genlogs.io/mismatch-observations' \
--header 'access-token: <your-api-token>' \
--header 'x-api-key: <your-x-api-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
  "usdots": ["10000", "200000", "300000"],
  "mcs": ["4000", "5000"],
  "pairs": [
    {
      "mc": "7894",
      "usdot": "9637"
    }
  ],
  "alert_name": "Custom mismatch trailer alert",
  "logos": ["<logo_from_list_logos>"]
}'
```

### **Response:**

* `201 Created`: Returns a confirmation message and the number of alerts created.
* `400 Bad Request`: Missing or invalid request parameters.
* `401 Unauthorized`: Missing, invalid, or expired `Access-Token`.
* `403 Forbidden`: The API key is missing or invalid, or your user does not have the required permission.
* `500 Internal Server Error`: Server error while processing the request.

### **Response Body:**

201 Created

The request example above creates 6 alerts: 3 USDOTs, 2 MCs, and 1 pair.

```json
{
    "message": "Mismatch alerts created successfully.",
    "data": {
        "created": 6
    }
}
```

400 Bad Request

```json
{
  "detail": "At least one USDOT, MC, or pair must be provided."
}
```

```json
{
  "detail": "failed import USDOT, should be numeric"
}
```

```json
{
  "detail": "Each pair must include both mc and usdot. Missing usdot in pairs[0]."
}
```

```json
{
  "detail": {
    "message": "One or more logos are invalid.",
    "invalid_logos": ["logo_name1"]
  }
}
```

```json
{
  "detail": "logos cannot contain more than 20 item(s)"
}
```

A property that is not allowed was sent:

```json
{
  "message": "Invalid request parameters: 'usdot'",
  "error_code": "VALIDATION_ERROR"
}
```

The body was not sent as JSON (for example, without the `Content-Type: application/json` header):

```json
{
  "message": "Invalid request parameters.",
  "error_code": "VALIDATION_ERROR"
}
```

401 Unauthorized

```json
{
  "message": "Access-Token header is missing",
  "error_type": "TokenMissingError",
  "error_code": "TOKEN_MISSING"
}
```

```json
{
  "message": "Authentication token has expired",
  "error_type": "TokenExpiredError",
  "error_code": "TOKEN_EXPIRED"
}
```

403 Forbidden

```json
{
  "message": "User not allowed to access this endpoint",
  "error_type": "PermissionError",
  "error_code": "PERMISSION_DENIED"
}
```

## Create mismatch observation alerts

> Creates one alert row per standalone USDOT or MC value, and one combined row per item in \`pairs\`. At least one of \`usdots\`, \`mcs\`, or \`pairs\` must be non-empty. \`alert\_name\` is optional; when omitted or blank, stored as null. \`logos\` is optional and, when present, is normalized to lowercase, stored in \`logos\`, and used by mismatch detection. Logo matching remains case-insensitive. Unknown JSON properties are rejected. USDOT and MC values must be numeric (leading zeros are removed); empty values are skipped and repeated values in the same request are created once. Values are not compared with existing alerts. Requires \`Content-Type: application/json\`.<br>

```json
{"openapi":"3.0.3","info":{"title":"Mismatch observation alerts (external API)","version":"1.4.0"},"servers":[{"url":"https://api.genlogs.io"}],"security":[{"Access-Token":[],"X-Api-Key":[]}],"components":{"securitySchemes":{"Access-Token":{"type":"apiKey","in":"header","name":"Access-Token"},"X-Api-Key":{"type":"apiKey","in":"header","name":"x-api-key"}},"schemas":{"ExternalMismatchObservationsRequest":{"type":"object","additionalProperties":false,"properties":{"usdots":{"type":"array","items":{"type":"string"},"description":"USDOT numbers (strings). Each non-empty entry creates one alert.","default":[]},"mcs":{"type":"array","items":{"type":"string"},"description":"MC numbers (strings). Each non-empty entry creates one alert.","default":[]},"pairs":{"type":"array","items":{"$ref":"#/components/schemas/MismatchObservationPairRequest"},"description":"Paired MC/USDOT identifiers. Each item creates one combined alert row with both MC and USDOT in the stored criteria.\n","default":[]},"logos":{"type":"array","nullable":true,"items":{"type":"string"},"description":"Optional trailer logos list. Each value must be a non-empty string. Values are trimmed, deduplicated, and stored in lowercase format. Matching against the logos catalog.\n"},"alert_name":{"type":"string","nullable":true,"description":"Optional display name; omitted or whitespace-only is stored as null."}}},"MismatchObservationPairRequest":{"type":"object","additionalProperties":false,"required":["mc","usdot"],"properties":{"mc":{"type":"string","minLength":1,"description":"MC number for the combined alert row."},"usdot":{"type":"string","minLength":1,"description":"USDOT number for the combined alert row."}}}}},"paths":{"/mismatch-observations":{"post":{"summary":"Create mismatch observation alerts","description":"Creates one alert row per standalone USDOT or MC value, and one combined row per item in `pairs`. At least one of `usdots`, `mcs`, or `pairs` must be non-empty. `alert_name` is optional; when omitted or blank, stored as null. `logos` is optional and, when present, is normalized to lowercase, stored in `logos`, and used by mismatch detection. Logo matching remains case-insensitive. Unknown JSON properties are rejected. USDOT and MC values must be numeric (leading zeros are removed); empty values are skipped and repeated values in the same request are created once. Values are not compared with existing alerts. Requires `Content-Type: application/json`.\n","tags":["Mismatch alerts"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExternalMismatchObservationsRequest"}}}},"responses":{"201":{"description":"Mismatch alerts created successfully.","content":{"application/json":{"schema":{"type":"object","required":["message","data"],"properties":{"message":{"type":"string"},"data":{"type":"object","properties":{"created":{"type":"integer","description":"Number of alerts inserted."}}}}}}}},"400":{"description":"Bad request – empty usdots/mcs/pairs, non-numeric USDOT or MC, invalid pair, invalid or too many logos, unknown property, or body not sent as JSON.\n","content":{"application/json":{}}},"401":{"description":"Unauthorized – Access-Token is missing, invalid, or expired.","content":{"application/json":{}}},"403":{"description":"Forbidden – missing permission.","content":{"application/json":{}}},"500":{"description":"Internal Server Error."}}}}}}
```
