> ## 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 Created

> Run an automation the moment a task of the chosen task type is created.

**On Task Created** runs immediately after a task of the chosen **Task Type** is created and saved. It lets you act on a task the moment it enters the system: place it, assign it, create its partner task, notify the customer or tell another system.

<Note>
  Required permission:

  * View automation
  * Create automation
</Note>

## When it runs

The event runs when a task is created by any of these:

* **Web app**: a user creates the task on the Task page.
* **Import**: tasks uploaded from a spreadsheet.
* **Field app**: a field worker creates the task.
* **API**: a task created through the API.
* **Automation**: a task created by another automation.
* **Schedule**: a task generated by a recurring schedule.

It runs only when 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. **Name**: for example "Create Delivery when Pickup is created".
3. **Event**: **On Task Created**.
4. **Task Type**: the task type to watch, for example **Pickup**.
5. **Automation Type**: one of
   * [Create Task](/pages/workflow/automation/actions/create-task)
   * [Create and Assign Task](/pages/workflow/automation/actions/create-and-assign-task)
   * [Move Task](/pages/workflow/automation/actions/move-task)
   * [Assign Task](/pages/workflow/automation/actions/assign-task)
   * [Update Task](/pages/workflow/automation/actions/update-task)
   * [Webhook](/pages/workflow/automation/actions/webhook)
   * [Notification](/pages/workflow/automation/actions/notification)
6. Optionally add **Rules**, fill in the **Automation detail**, and click **Submit**.
7. Make sure the automation's **Active** switch is on, then create a task of that task type to test it.

## Use cases

| Scenario | Task Type | Automation Type | Result |
| - | - | - | - |
| Pair pickups and deliveries | Pickup | Create Task | A Delivery task is created with the pickup's details. |
| Sync to a CRM, ERP or WMS | Customer Visit | Webhook | The new task's data is sent to your system. |
| Confirm the order to the customer | Delivery | Notification | The customer gets a WhatsApp message with the tracking link. |
| Route VIP orders to one driver | Delivery | Assign Task | Tasks matching a rule are assigned at once. |
| Fill in derived fields | Delivery | Update Task | Fields of the new task are set from its own values. |

## Task type matching

The automation checks the task type of every new task:

| Automation's Task Type | Task created with | Runs? |
| - | - | - |
| Delivery | Delivery | Yes |
| Delivery | Pickup | No |
| Delivery | Visit | No |

You can create several automations on the same event for different task types, for example On Task Created › Delivery › send to the ERP, and On Task Created › Pickup › send to the WMS. Each runs on its own.

## Webhook payload

With the [Webhook](/pages/workflow/automation/actions/webhook) action, the request body carries the new task. An example:

```json theme={null}
{
  "event": "on_task_created",
  "timestamp": "2024-01-15T10:30: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",
    "status": "unassigned",
    "priority": "normal",
    "paymentType": ["COD"],
    "customFields": {
      "notes": "Handle with care",
      "specialInstructions": "Call before delivery"
    }
  },
  "hub": { "id": "hub_id_789", "name": "Jakarta Hub" },
  "creator": { "id": "user_id_101", "name": "Operations Manager", "email": "ops@example.com" },
  "createdFrom": "WEB"
}
```

The exact fields depend on the components of your task type. Use the **Sample payload** box of the webhook's **Custom JSON body** to see the keys you can map. The [automation log](/pages/workflow/automation/log) shows the exact request that was sent.

## Troubleshooting

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

* Check that its **Active** switch is on.
* Check that the task's task type matches the automation's **Task Type**.
* Check that the [rules](/pages/workflow/automation/rules) don't exclude the task.
* Open the [log](/pages/workflow/automation/log) and look for failed runs.

**The webhook receives incomplete task data.**

* Optional fields that were left empty when the task was created are not sent. Handle missing keys in your endpoint.
* Tasks created through the API with minimal data carry only what was sent.

**The automation runs more than once for the same task.**

* Look for several active automations on the same task type.
* Make sure you chose On Task Created and not On Task Finished.
* Make your endpoint idempotent, using the task ID.

**Tasks are created in a loop.**

* An automation that creates a task of the same task type it watches triggers itself. The **Create Task** list doesn't offer the trigger's own task type, but two automations can still feed each other. Use different task types, or add rules that stop the chain.


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