> ## 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 Finish Trip

> Send a webhook when a field worker ends a trip in the field app.

**On Finish Trip** runs when a field worker taps **End Trip** in the field app and the trip end is recorded. It's the place to close the day in other systems: trip summaries, fleet availability, expense reporting.

The event belongs to the **Location History** group. It has no task type and no rules: every trip end in your organization triggers it.

<Note>
  Required permission:

  * View automation
  * Create automation
</Note>

## Before you start

* Field workers use the field app, and the start trip / end trip feature is turned on for your organization.
* A trip can only end after it was started.
* The event can only come from the field app.

## Set it up

1. On **Workflow › Automation**, click **New**.
2. **Event**: **On Finish Trip**.
3. **Automation Type**: **Webhook**, the only type this event allows.
4. Fill in the [webhook](/pages/workflow/automation/actions/webhook) **URL** and **Headers**, for example `https://api.example.com/trip/end` with an `Authorization` header.
5. Click **Submit** and make sure the automation is **Active**.

## Use cases

| Scenario | What your endpoint does |
| - | - |
| Fleet availability | Marks the vehicle "Available" and logs the distance traveled. |
| Trip summary | Stores start and end time, duration and completed tasks for reporting. |
| Post-trip work | Opens an expense or vehicle-check item in your own system. |

## Webhook payload

An example request body. `duration` is in seconds:

```json theme={null}
{
  "event": "on_finish_trip",
  "timestamp": "2024-01-15T17:45:00.000Z",
  "user": {
    "id": "user_id_123",
    "name": "Budi Santoso",
    "email": "budi@example.com",
    "phone": "+6281234567890"
  },
  "trip": {
    "id": "trip_id_789",
    "startTime": "2024-01-15T08:30:00.000Z",
    "endTime": "2024-01-15T17:45:00.000Z",
    "duration": 33300,
    "durationFormatted": "9 hours 15 minutes",
    "startLocation": { "latitude": -6.2088, "longitude": 106.8456, "address": "Jakarta, Indonesia" },
    "endLocation": { "latitude": -6.2015, "longitude": 106.852, "address": "Jakarta, Indonesia" },
    "tasksCompleted": 12,
    "totalTasks": 15,
    "distanceTraveled": 85.3
  },
  "hub": { "id": "hub_id_456", "name": "Jakarta Hub" }
}
```

## Troubleshooting

**The automation doesn't run when a trip ends.**

* Check that its **Active** switch is on.
* Check that the trip was started first.
* A field worker without a connection sends the trip end when they come back online.
* Look at the [log](/pages/workflow/automation/log) for failed runs.


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