> ## 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 Task Finished

> Run an automation when a task of the chosen task type is finished.

**On Task Finished** runs when a task of the chosen **Task Type** is finished. It's the most common trigger for chaining work, sending proof of delivery to another system, or writing the results back to a data source.

<Note>
  Required permission:

  * View automation
  * Create automation
</Note>

## When it runs

The event runs when:

1. A field worker finishes the task in the field app,
2. a user marks the task as finished in the web app, or
3. the task is finished through the API,

and the task's task type matches the automation's **Task Type** and the task matches every [rule](/pages/workflow/automation/rules).

## Set it up

1. On **Workflow › Automation**, click **New**.
2. **Event**: **On Task Finished**.
3. **Task Type**: the task type to watch, for example **Delivery**.
4. **Automation Type**: one of
   * [Create Task](/pages/workflow/automation/actions/create-task)
   * [Create and Assign Task](/pages/workflow/automation/actions/create-and-assign-task)
   * [Create or Update Data Source](/pages/workflow/automation/actions/create-or-update-data-source)
   * [Webhook](/pages/workflow/automation/actions/webhook)
   * [Notification](/pages/workflow/automation/actions/notification)
5. Fill in the **Automation detail** and click **Submit**.

## Use cases

| Scenario | Task Type | Automation Type | Result |
| - | - | - | - |
| Create the next step | Delivery | Create and Assign Task | A Pickup task is created and assigned to the same driver, in the hub where the delivery was finished. |
| Tell the customer it's done | Delivery | Notification | The customer gets a message or email. |
| Archive proof of delivery | Delivery | Webhook | Photos, signature and notes are sent to your document system. |
| Keep master data current | Visit | Create or Update Data Source | The visit's customer details update the Customer data source. |

## Webhook payload

An example request body:

```json theme={null}
{
  "event": "on_task_finished",
  "timestamp": "2024-01-15T16:45:00.000Z",
  "task": {
    "id": "task_id_123",
    "flow": "Delivery",
    "flowId": "flow_id_456",
    "invoice": "INV-2024-001",
    "name": "Budi Santoso",
    "phone": "+6281234567890",
    "address": "Jl. Sudirman No. 123, Jakarta",
    "deliveryCoordinate": "-6.2088,106.8456",
    "startTime": "2024-01-15T14:00:00.000Z",
    "endTime": "2024-01-15T16:00:00.000Z",
    "completedTime": "2024-01-15T16:45:00.000Z",
    "status": "finished",
    "completionStatus": "success",
    "duration": 9900,
    "priority": "normal",
    "proofOfDelivery": {
      "photos": [
        "https://storage.example.com/tasks/photo1.jpg",
        "https://storage.example.com/tasks/photo2.jpg"
      ],
      "signature": "https://storage.example.com/tasks/signature.png",
      "notes": "Package delivered successfully"
    }
  },
  "assignee": {
    "id": "user_id_789",
    "name": "Field Worker Name",
    "email": "worker@example.com",
    "phone": "+6281234567891"
  },
  "hub": { "id": "hub_id_789", "name": "Jakarta Hub" },
  "completedBy": { "id": "user_id_789", "name": "Field Worker Name" }
}
```

The exact fields depend on your task type. The [automation log](/pages/workflow/automation/log) shows the exact request that was sent.

## Troubleshooting

**The automation doesn't run when tasks are finished.**

* Check that its **Active** switch is on and the task type matches.
* Check that the rules don't exclude the task.
* The task must actually reach the finished (done) status.

**The webhook receives incomplete data.**

* Optional fields left empty during the task are not sent.
* Photos or signatures may be missing if the field app finished the task before its uploads were synced. Ask field workers to stay online until the task syncs, and handle missing keys in your endpoint.


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