> ## Documentation Index
> Fetch the complete documentation index at: https://docsv4.mile.app/llms.txt
> Use this file to discover all available pages before exploring further.

# On Alert Created

> Create a task, call your system or send an email when MileApp raises an alert of the type you choose.

**On Alert Created** runs when MileApp raises a monitoring [alert](https://docsv4.mile.app/pages/monitoring/alert.md) of the type you choose, for example an SOS from the panic button, an overspeed or a low battery. Use it to open a follow-up task for the alert, push it to your own system, or email the people who must react.

The event belongs to the **Alert** group, with [On Alert Resolved](https://docsv4.mile.app/pages/workflow/automation/events/on-alert-resolved.md).

> [!NOTE]
>
> Required permission:
>
> * View automation
> * Create automation

## Constraints

1. **One alert type per automation.** The automation watches exactly one **Alert type**. To react to several types, add one trigger per type.
2. **Three actions.** [Create Task](https://docsv4.mile.app/pages/workflow/automation/actions/create-task.md), [Webhook](https://docsv4.mile.app/pages/workflow/automation/actions/webhook.md) and [Notification](https://docsv4.mile.app/pages/workflow/automation/actions/notification.md) by **Email**. WhatsApp and SMS are not offered on alert events.
3. **No rules.** The alert type is the automation's only scope.
4. **Saved in an automation group.** Alert events are set up on the automation group canvas. They can't be created through `POST /automation`.

## Alert types

| Alert type | Code (`alertCode`) |
| - | - |
| SOS: Panic | `user.panic` |
| Speed: Overspeed | `overspeed.detected` |
| Geofence: Enter | `geofence.enter` |
| Geofence: Leave | `geofence.leave` |
| Idle: Detected | `idle.detected` |
| Task: Late | `task.lateness.predicted` |
| Route: Deviation | `route.deviation.detected` |
| Device: Low battery | `device.battery.low` |

An alert type switched off in [Alert Setting](https://docsv4.mile.app/pages/settings/alert-setting.md) is never raised, so it never runs this event.

## When it runs

1. A detector or the field app raises an alert, for example a driver presses the panic button.
2. The alert is saved and appears in **Monitoring › Alert**.
3. Every active automation whose **Alert type** matches the alert's code runs its action.

It does **not** run for:

* **Repeats.** While a driver keeps overspeeding, or a battery stays low, the alert is raised again with **Repeated** set. Only the first alert runs the event.
* **Alerts raised by an automation.** An alert from the **Alert** action (`automation.alert`) never starts an alert event, so automations can't trigger each other in a loop.
* **Other codes.** Only the eight alert types above can be chosen.

## Set it up

1. Open **Workflow › Automation** and create or open an automation group.
2. In **Add first step**, under **Alert**, pick **On Alert Created**.
3. **Alert type**: required. Pick the one type to watch, for example **Device: Low battery**.
4. Click **+** under the trigger and pick an action in **Add Automation**:
   * **Create Task**: pick the flow and the **Hub**, then fill each task field with a value or an alert field from the search button.
   * **Webhook**: fill in the **URL** and any headers.
   * **Notification**: the channel is **Email**. The alert's user is also sent the email, on top of the recipients you choose.
5. Click **Save**, and switch the group on.

Test it by raising an alert of that type, for example by pressing the panic button in the field app for **SOS: Panic**.

## Alert fields

The same fields fill a Create Task mapping, an email's variables and the webhook body. In the app they show by their label; the key is what a webhook receives.

| Label | Key | Description |
| - | - | - |
| Alert Code | `alertCode` | The alert type's code, for example `device.battery.low`. |
| Alert Name | `alertName` | The alert type's name. |
| Title | `title` | The alert's title. |
| Message | `message` | The alert's message, as shown in Monitoring › Alert. |
| Assignee | `assignee` | Email of the field worker the alert is about. |
| Hub ID | `hubId` | ID of the hub the alert belongs to. |
| Event Time | `eventTime` | When the alert happened. |
| Created Time | `createdTime` | When the alert was saved. |
| Updated Time | `updatedTime` | When the alert last changed. |
| Resolved | `isResolved` | Always `false` on this event. |

The webhook body also carries `docId` (the alert's ID) and `organizationId`.

Each alert type adds its own details under `data`. In the app they are labelled **Data …**, for example **Data Driver Name**:

| Alert type | Fields under `data` |
| - | - |
| SOS: Panic | `driverName`, `phone`, `address`, `lat`, `lon`, `locationSource`, `locationTime`, `userId`, `trackingDate` |
| Speed: Overspeed | `driverName`, `speed`, `limit`, `isRepeat`, `consecutive`, `repeat`, `lat`, `lon`, `locationHistoryId`, `trackingDate` |
| Geofence: Enter | `driverName`, `geofenceId`, `geofenceName`, `geofenceGroup`, `enteredAt`, `dwellMinutes`, `lat`, `lon`, `locationHistoryId`, `trackingDate` |
| Geofence: Leave | `driverName`, `geofenceId`, `geofenceName`, `geofenceGroup`, `enteredAt`, `dwelledMinutes`, `lat`, `lon`, `locationHistoryId`, `trackingDate` |
| Idle: Detected | `driverName`, `isRepeat`, `idleSince`, `idled`, `reported`, `window`, `windowSamples`, `averageDistance`, `pingDistance`, `threshold`, `repeat`, `lat`, `lon`, `locationHistoryId`, `trackingDate` |
| Task: Late | `driverName`, `trigger`, `taskId`, `taskTitle`, `eta`, `etaAt`, `estimatedArrival`, `delayMinutes`, `travelTimeMinutes`, `graceMinutes`, `anchorDate`, `orderIndex`, `lat`, `lon`, `locationHistoryId`, `trackingDate` |
| Route: Deviation | `driverName`, `routingResultId`, `distanceMeters`, `thresholdMeters`, `consecutivePings`, `firstOffRouteAt`, `lat`, `lon`, `locationHistoryId`, `trackingDate` |
| Device: Low battery | `driverName`, `battery`, `limit`, `isRepeat`, `repeat`, `lat`, `lon`, `locationHistoryId`, `trackingDate` |

A field the alert did not record is empty.

## Webhook payload

An example for **Device: Low battery**:

```json theme={null}
{
  "docId": "6731c0e89a8ee9d8830baac2",
  "organizationId": "660a1b2c4f1a2b3c4d5e6f03",
  "alertCode": "device.battery.low",
  "alertName": "Low battery",
  "title": "Low battery",
  "message": "Budi's phone battery is at 14%.",
  "assignee": "budi@example.com",
  "hubId": "6ae400a6ea63638295070382",
  "eventTime": "2026-11-10T03:15:00+00:00",
  "createdTime": "2026-11-10T03:15:02+00:00",
  "updatedTime": "2026-11-10T03:15:02+00:00",
  "isResolved": false,
  "data": {
    "driverName": "Budi",
    "battery": 14,
    "limit": 15,
    "isRepeat": false,
    "repeat": 30,
    "lat": -6.2088,
    "lon": 106.8456,
    "locationHistoryId": "6731c0e19a8ee9d8830baab7",
    "trackingDate": "2026-11-10"
  }
}
```

A failed webhook is tried up to four times. Your endpoint must answer with HTTP 200.

## Troubleshooting

**The event never runs.**

* Check that the automation group is switched on.
* Check the trigger's **Alert type** is the type that was raised.
* The alert type may be switched off in [Alert Setting](https://docsv4.mile.app/pages/settings/alert-setting.md), so no alert was raised. Check **Monitoring › Alert**.
* A repeat of an alert that is already open does not run the event.

**The email reaches only the field worker.** The alert's user always receives it. Add the other recipients in the Notification's **To**.

**The webhook receives nothing.** Check the URL is reachable from the internet and the authentication header, then read the response in the [log](https://docsv4.mile.app/pages/workflow/automation/log.md).

## Questions

**Can one trigger watch several alert types?** No. Add one **On Alert Created** trigger per type; they can sit in the same automation group.

**Can I filter, for example only overspeeds above 100 km/h?** Not yet. The alert type is the only scope.

**Does an automation's own Alert action start this event?** No, see [When it runs](#when-it-runs).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.