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

# Automation

> Automation enables you to set up automation based on tasks' events and data source's events

## What is Automation?

Automation enables you to set up automation based on tasks' events and data source's events. It might help you automate creation of tasks, task assignment, task placement, task webhook, data source update, datasource creation, data source webhook, and task component updates. Automation attributes consist of IDs, automation name, automation type, automation details, and rules. Automation logs are stored with 30-day data retention.

## Automation Types

| Type | Description |
| - | - |
| Create Task | Create a new task in a specified flow |
| Create and Assign Task | Create a task and immediately assign it |
| Move Task | Transition a task to a different hub |
| Assign Task | Assign users to a task |
| Update Task | Update the triggering task's own components with static values, references to other task fields, or values from a linked data source record |
| Webhook | Call an external HTTP endpoint |
| Create or Update Data Source | Create or update a Data Source record |
| Notification | Send a notification via messaging channel |

For **Update Task**, a field value can also be sourced from a record in a data source linked to the triggering task ("From Data Source"). The picker shows only the data source fields that are **mapped** in the flow's data source configuration (the primary key is the lookup, not a selectable value). The value is fetched at the system level, so it works even when the field is restricted for the user who created the task.

## Automation Events

The `event` field accepts one of ten values across four data types.

| Data Type | Events |
| - | - |
| `task` | `onTaskCreated`, `onTaskAssigned`, `onTaskFinished` |
| `data` | `onDataSourceCreated` |
| `routingResult` | `onRoutingResultFinished`, `onRoutingResultDispatched` |
| `locationHistory` | `onStartTrip`, `onFinishTrip`, `onGeofenceEntry`, `onGeofenceLeave` |

Any other value is rejected with `400 Bad Request`.

### Geofence Events

`onGeofenceEntry` and `onGeofenceLeave` fire when a field worker's GPS position crosses into or out of a geofence. They carry two constraints the other events do not:

* **`automationType` must be `webhook`.** Every other type is rejected with `400 Bad Request`.
* **`rules.fields.geofenceGroupId` is required.** The automation is scoped to exactly one geofence group, and the request fails validation without it. Do not send `rules.schema`: the API derives it from the keys of `rules.fields` and overwrites anything you send.

```json theme={null}
{
  "name": "Notify WMS when a driver reaches a store",
  "event": "onGeofenceEntry",
  "automationType": "webhook",
  "dataType": "locationHistory",
  "automationDetails": {
    "url": "https://api.partner.com/webhook/geofence-entry",
    "headers": [
      { "key": "Authorization", "value": "Bearer wms_token_abc123" }
    ]
  },
  "rules": {
    "fields": {
      "geofenceGroupId": "66c1a4f2d3b19f0012ab77e4"
    }
  },
  "isActive": true
}
```

Geofence is not generally available yet. It is enabled for internal staff and explicitly allowlisted pilot organizations. Every geofence endpoint returns **404 Not Found** for organizations outside the rollout, not 403. See [On Geofence Entry](/pages/automation/automation-event/on-geofence-entry) and [On Geofence Leave](/pages/automation/automation-event/on-geofence-leave) for the webhook payload.

**To see the details of automation object, please follow [this link](/api-reference/objects/automation-object)**

## Key Features

<CardGroup cols={2}>
  <Card title="Read automation" icon="list" href="/api-reference/flow/automation/read-automation">
    GET /automations
  </Card>

  <Card title="Read log automation" icon="list" href="/api-reference/flow/automation/read-log-automation">
    GET /automation-log
  </Card>

  <Card title="Read automation by ID" icon="list" href="/api-reference/flow/automation/read-automation-by-id">
    GET /automation/{automationId}
  </Card>

  <Card title="Create automation" icon="plus" href="/api-reference/flow/automation/create-automation">
    POST /automation
  </Card>
</CardGroup>

## Related Resources

* [Automation Object](/api-reference/objects/automation-object) - Automation data structure
* [On Geofence Entry](/pages/automation/automation-event/on-geofence-entry) - Geofence entry event and webhook payload
* [On Geofence Leave](/pages/automation/automation-event/on-geofence-leave) - Geofence leave event and webhook payload
