> For the complete documentation index, see [llms.txt](https://teamleader-sdk.mcore-services.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://teamleader-sdk.mcore-services.dev/api-reference/projects/project-tasks.md).

# Project Tasks

Manage tasks in Teamleader Focus projects.

Tasks in the current ("nextgen") project system — `projects-v2/tasks.*`.

For the older task system, see `Tasks`.

```php
Teamleader::projectTasks()
```

|                          |                                                                       |
| ------------------------ | --------------------------------------------------------------------- |
| Class                    | `McoreServices\TeamleaderSDK\Resources\Projects\ProjectTasks`         |
| Create / update / delete | ✓ / ✓ / ✓                                                             |
| Pagination               | `page_size` / `page_number`; no totals — a short page is the last one |

## Endpoints

* `projects-v2/tasks.assign`
* `projects-v2/tasks.create`
* `projects-v2/tasks.delete`
* `projects-v2/tasks.duplicate`
* `projects-v2/tasks.info`
* `projects-v2/tasks.list`
* `projects-v2/tasks.unassign`
* `projects-v2/tasks.update`

## Filters

Passed as the first argument to `list()`. Any other key throws.

| Filter | Description         |
| ------ | ------------------- |
| `ids`  | Array of task UUIDs |

## Accepted values

Public constants on the class. Body fields and enum values outside these lists throw before the request is sent.

| Constant            | Values                                                                                                                                                                                                                          |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ASSIGNEE_TYPES`    | `team`, `user`                                                                                                                                                                                                                  |
| `BILLING_METHODS`   | `user_rate`, `work_type_rate`, `custom_rate`, `fixed_price`, `parent_fixed_price`, `non_billable`                                                                                                                               |
| `COLORS`            | `#00B2B2`, `#008A8C`, `#992600`, `#ED9E00`, `#D157D3`, `#A400B2`, `#0071F2`, `#004DA6`, `#64788F`, `#C0C0C4`, `#82828C`, `#1A1C20`                                                                                              |
| `CREATE_FIELDS`     | `project_id`, `title`, `group_id`, `work_type_id`, `task_type_id`, `description`, `billing_method`, `fixed_price`, `external_budget`, `internal_budget`, `custom_rate`, `start_date`, `end_date`, `time_estimated`, `assignees` |
| `CURRENCIES`        | `BAM`, `CAD`, `CHF`, `CLP`, `CNY`, `COP`, `CZK`, `DKK`, `EUR`, `GBP`, `INR`, `ISK`, `JPY`, `MAD`, `MXN`, `NOK`, `PEN`, `PLN`, `RON`, `SEK`, `TRY`, `USD`, `ZAR`                                                                 |
| `DELETE_STRATEGIES` | `unlink_time_tracking`, `delete_time_tracking`                                                                                                                                                                                  |
| `STATUSES`          | `to_do`, `in_progress`, `on_hold`, `done`                                                                                                                                                                                       |
| `TIME_UNITS`        | `hours`, `minutes`, `seconds`                                                                                                                                                                                                   |
| `UPDATE_FIELDS`     | `work_type_id`, `task_type_id`, `status`, `title`, `description`, `billing_method`, `fixed_price`, `external_budget`, `internal_budget`, `custom_rate`, `start_date`, `end_date`, `time_estimated`                              |
| `UPDATE_STRATEGIES` | `none`, `cascade`                                                                                                                                                                                                               |

## Methods

### `list()`

```php
list(array $filters = [], array $options = []): array
```

List tasks

Before v2.2.9 any filter was a fatal error: list() called a buildFilters() method the class did not define.

* `$filters` — ids (a UUID or a list of UUIDs)
* `$options` — page\_size, page\_number

**Throws** `InvalidArgumentException` On an unknown filter key or option

### `info()`

```php
info($id, $includes = null): array
```

Get one task

* `$id` — Task UUID
* `$includes` — tasks.info takes no includes; passing any throws

### `create()`

```php
create(array $data): array
```

Create a task

Requires project\_id and title. With billing\_method `work_type_rate`, a work\_type\_id is required as well.

**Throws** `InvalidArgumentException` When a required field is missing, or a field or value is not accepted

### `update()`

```php
update($id, array $data): array
```

Update a task

Every field is optional; null clears a nullable field.

* `$id` — Task UUID

**Throws** `InvalidArgumentException` When a field or value is not accepted

### `delete()`

```php
delete($id, ...$additionalParams): array
```

Delete a task

* `$id` — Task UUID
* `$additionalParams` — Delete strategy: unlink\_time\_tracking (default) or delete\_time\_tracking

**Throws** `InvalidArgumentException`

### `duplicate()`

```php
duplicate(string $originId): array
```

Duplicate a task (without its time trackings)

* `$originId` — UUID of the task to duplicate

### `byIds()`

```php
byIds(array $ids): array
```

Get tasks by ID

* `$ids` — Task UUIDs

### `updateStatus()`

```php
updateStatus(string $taskId, string $status): array
```

Update a task's status

* `$status` — to\_do, in\_progress, on\_hold or done

### `getResponseStructure()`

```php
getResponseStructure(): array
```

Get response structure documentation

### `assign()`

```php
assign(string $id, string $assigneeType, string $assigneeId): array
```

Assign a user or team

* `$id` — UUID of the project, group, task or material
* `$assigneeType` — user or team
* `$assigneeId` — UUID of the user or team

**Throws** `InvalidArgumentException` When the assignee type is not user or team

### `unassign()`

```php
unassign(string $id, string $assigneeType, string $assigneeId): array
```

Unassign a user or team

* `$id` — UUID of the project, group, task or material
* `$assigneeType` — user or team
* `$assigneeId` — UUID of the user or team

**Throws** `InvalidArgumentException` When the assignee type is not user or team

### `assignUser()`

```php
assignUser(string $id, string $userId): array
```

### `assignTeam()`

```php
assignTeam(string $id, string $teamId): array
```

### `unassignUser()`

```php
unassignUser(string $id, string $userId): array
```

### `unassignTeam()`

```php
unassignTeam(string $id, string $teamId): array
```

### `getAvailableAssigneeTypes()`

```php
getAvailableAssigneeTypes(): array
```

## Examples

Get all tasks:

```php
$tasks = Teamleader::projectTasks()->list();
```

Create a new task:

```php
$task = Teamleader::projectTasks()->create([
    'project_id' => 'uuid',
    'title' => 'Write API documentation',
    'billing_method' => 'user_rate'
]);
```

Update task status:

```php
$task = Teamleader::projectTasks()->update('task-uuid', [
    'status' => 'in_progress'
]);
```

Assign a user to a task:

```php
Teamleader::projectTasks()->assign('task-uuid', 'user', 'user-uuid');
```

Delete a task and unlink time tracking:

```php
Teamleader::projectTasks()->delete('task-uuid', 'unlink_time_tracking');
```
