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

# Tasks API

> API endpoints for managing work order tasks

## Overview

The Tasks API allows you to manage individual tasks within work orders. Tasks represent specific work items that need to be completed as part of a work order.

***

## Endpoints

### List Tasks

Retrieve tasks for a work order.

```
GET /api/v1/work-orders/{work_order_id}/tasks
```

**Query Parameters:**

| Parameter       | Type   | Description                   |
| --------------- | ------ | ----------------------------- |
| `status`        | string | Filter by status              |
| `technician_id` | string | Filter by assigned technician |

**Example Request:**

```bash theme={null}
curl -X GET "https://api.fentu.io/v1/work-orders/wo-12345/tasks" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

**Example Response:**

```json theme={null}
{
  "data": [
    {
      "id": "task-001",
      "name": "Inspect Machine filters",
      "description": "Check and document filter condition",
      "status": "completed",
      "technician": {
        "id": "tech-001",
        "name": "Jane Doe"
      },
      "started_at": "2024-01-27T09:30:00Z",
      "completed_at": "2024-01-27T09:45:00Z",
      "duration": 15
    },
    {
      "id": "task-002",
      "name": "Replace filters",
      "status": "pending",
      "parts_required": [
        {
          "part_id": "part-001",
          "name": "Air Filter 20x25",
          "quantity": 2
        }
      ]
    }
  ]
}
```

***

### Get Task

Retrieve a single task.

```
GET /api/v1/tasks/{id}
```

**Example Response:**

```json theme={null}
{
  "data": {
    "id": "task-001",
    "work_order_id": "wo-12345",
    "name": "Inspect Machine filters",
    "description": "Check and document filter condition",
    "status": "completed",
    "sequence": 1,
    "estimated_duration": 15,
    "actual_duration": 15,
    "technician": {
      "id": "tech-001",
      "name": "Jane Doe"
    },
    "checklist": {
      "id": "checklist-001",
      "name": "Filter Inspection"
    },
    "parts_used": [
      {
        "part_id": "part-001",
        "name": "Air Filter 20x25",
        "quantity": 1
      }
    ],
    "notes": "Filter was heavily clogged",
    "photos": [
      {
        "id": "photo-001",
        "url": "https://..."
      }
    ],
    "started_at": "2024-01-27T09:30:00Z",
    "completed_at": "2024-01-27T09:45:00Z"
  }
}
```

***

### Create Task

Add a task to a work order.

```
POST /api/v1/work-orders/{work_order_id}/tasks
```

**Request Body:**

```json theme={null}
{
  "name": "Install new thermostat",
  "description": "Remove old thermostat and install new smart thermostat",
  "estimated_duration": 45,
  "technician_id": "tech-001",
  "checklist_id": "checklist-002",
  "parts": [
    {
      "part_id": "part-002",
      "quantity": 1
    }
  ]
}
```

**Example Request:**

```bash theme={null}
curl -X POST "https://api.fentu.io/v1/work-orders/wo-12345/tasks" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Install new thermostat",
    "estimated_duration": 45
  }'
```

***

### Update Task

Update a task.

```
PUT /api/v1/tasks/{id}
```

**Request Body:**

```json theme={null}
{
  "status": "completed",
  "actual_duration": 40,
  "notes": "Installation completed successfully",
  "parts_used": [
    {
      "part_id": "part-002",
      "quantity": 1
    }
  ]
}
```

***

### Delete Task

Remove a task from a work order.

```
DELETE /api/v1/tasks/{id}
```

***

### Complete Task

Mark a task as completed.

```
POST /api/v1/tasks/{id}/complete
```

**Request Body:**

```json theme={null}
{
  "notes": "Task completed successfully",
  "photos": ["photo-base64-data"],
  "parts_used": [
    {
      "part_id": "part-001",
      "quantity": 2
    }
  ],
  "checklist_responses": [
    {
      "item_id": "item-001",
      "response": true
    }
  ]
}
```

***

## Task Statuses

| Status        | Description                           |
| ------------- | ------------------------------------- |
| `pending`     | Not yet started                       |
| `in_progress` | Currently being worked on             |
| `completed`   | Successfully finished                 |
| `skipped`     | Not performed (with reason)           |
| `blocked`     | Cannot proceed (waiting on something) |

***

## Task Line Items

Tasks can have associated line items for billing:

### List Line Items

```
GET /api/v1/tasks/{task_id}/line-items
```

### Add Line Item

```
POST /api/v1/tasks/{task_id}/line-items
```

**Request Body:**

```json theme={null}
{
  "type": "labor",
  "description": "Installation labor",
  "quantity": 1,
  "unit_price": 75.00,
  "tax_rate": 0.08
}
```

***

## Error Responses

| Code  | Description                          |
| ----- | ------------------------------------ |
| `400` | Bad request - invalid parameters     |
| `401` | Unauthorized                         |
| `403` | Forbidden - insufficient permissions |
| `404` | Task or work order not found         |
| `422` | Validation error                     |

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Work Orders API" icon="clipboard-list" href="/api-reference/endpoints/work-orders">
    Work order endpoints
  </Card>

  <Card title="Tasks" icon="tasks" href="/work-orders/tasks">
    Task user guide
  </Card>

  <Card title="Authentication" icon="key" href="/api-reference/authentication">
    API authentication
  </Card>

  <Card title="Parts API" icon="cogs" href="/inventory/parts">
    Parts management
  </Card>
</CardGroup>
