> For the complete documentation index, see [llms.txt](https://docs.api.intratool.de/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.api.intratool.de/api-reference/tasks-2/task-assignments.md).

# TaskAssignments

## Introduction

`TaskAssignments` define when and for whom tasks should be executed.

Assignment data and related [TaskTemplates](/api-reference/tasks-2/task-templates.md) are used to create [TaskExecutions](/api-reference/tasks-2/task-executions.md) for users and departments.

## Model Definition

**Alias**

`taskAssignment`

**Relations**

| Relation                                                    | Key            | Type            | Relation Field(s)         |
| ----------------------------------------------------------- | -------------- | --------------- | ------------------------- |
| [TaskTemplate](/api-reference/tasks-2/task-templates.md)    | `taskTemplate` | Belongs to      | `task_template_id`        |
| [Departments](/api-reference/departments.md)                | `departments`  | Belongs to many | Intermediate table        |
| [Users](/api-reference/users.md)                            | `users`        | Belongs to many | Intermediate table        |
| [User](/api-reference/users.md)                             | `creator`      | Belongs to      | `user_id`                 |
| [TaskExecutions](/api-reference/tasks-2/task-executions.md) | `tasks`        | Has many        | `task.task_assignment_id` |

## \[Adm.] List

**Definition**

<mark style="color:green;">`GET`</mark> `/api/administration/tasks-2/assignments`

**Request Keys**

No additional request keys.

**Example Request**

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/tasks-2/assignments', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

**Example Response**

```json
[
  {
    "id": 80,
    "title": "Morning Shift",
    "task_template_id": 31,
    "assign_mode": "any_of",
    "active": true
  }
]
```

## \[Adm.] Show

**Definition**

<mark style="color:green;">`GET`</mark> `/api/administration/tasks-2/assignments/{taskAssignment}`

**Request Keys**

| Key              | Type    | Default | Description       |
| ---------------- | ------- | ------- | ----------------- |
| `taskAssignment` | integer | -       | TaskAssignment ID |

**Example Request**

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/tasks-2/assignments/80', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

**Example Response**

```json
{
  "id": 80,
  "title": "Morning Shift",
  "task_template_id": 31,
  "assign_mode": "any_of",
  "active": true,
  "reset_allowed": true
}
```

## \[Adm.] Create

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/administration/tasks-2/assignments`

**Request Keys**

| Key                          | Type     | Default      | Description                                                                |
| ---------------------------- | -------- | ------------ | -------------------------------------------------------------------------- |
| `title`\*                    | string   | -            | Assignment title.                                                          |
| `description`                | string   | `null`       | Assignment description (HTML).                                             |
| `task_template_id`\*         | integer  | -            | Related [TaskTemplate](/api-reference/tasks-2/task-templates.md) ID.       |
| `creator_user_id`            | integer  | current user | Creator user ID.                                                           |
| `assign_mode`                | string   | `all`        | Assignment mode (`all`, `any_of`, `one_of`, `any_of_user`, `one_of_user`). |
| `start_date`                 | date     | `null`       | Start date (`YYYY-MM-DD`).                                                 |
| `start_time`                 | time     | `null`       | Start time (`H:i:s`).                                                      |
| `show_before_interval`       | interval | `null`       | Visibility lead interval (ISO 8601 duration).                              |
| `executable_before_interval` | interval | `null`       | Executable-before interval (ISO 8601 duration).                            |
| `executable_after_interval`  | interval | `null`       | Executable-after interval (ISO 8601 duration).                             |
| `interval`                   | string   | `null`       | iCal RRULE.                                                                |
| `interval_end`               | date     | `null`       | End date for recurrence.                                                   |
| `active`                     | boolean  | `true`       | Active state.                                                              |
| `always_executable`          | boolean  | `false`      | Allows execution without time restrictions.                                |
| `user_confirmation_required` | boolean  | `true`       | Requires real-user confirmation.                                           |
| `delayed_reason_required`    | boolean  | `true`       | Requires delayed reason for delayed finish.                                |
| `deny_reason_required`       | boolean  | `true`       | Requires deny reason on deny action.                                       |
| `reset_allowed`              | boolean  | `true`       | Allows reset action for related executions.                                |
| `sort_number`                | integer  | auto         | Sort number.                                                               |
| `department_ids`             | array    | `[]`         | Target departments.                                                        |
| `user_ids`                   | array    | `[]`         | Target users.                                                              |

**Example Request**

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/administration/tasks-2/assignments', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'title' => 'Morning Shift',
        'task_template_id' => 31,
        'assign_mode' => 'any_of',
        'active' => true,
        'reset_allowed' => true,
        'user_ids' => [144]
    ]
]);
```

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 80,
    "title": "Morning Shift",
    "task_template_id": 31,
    "assign_mode": "any_of",
    "active": true,
    "reset_allowed": true
  }
}
```

## Create quick assignment

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/tasks-2/assignments/quick-assignment`

**Request Keys**

| Key                  | Type    | Default | Description                                                                        |
| -------------------- | ------- | ------- | ---------------------------------------------------------------------------------- |
| `title`\*            | string  | -       | Assignment title.                                                                  |
| `task_template_id`\* | integer | -       | Related quick-assignable [TaskTemplate](/api-reference/tasks-2/task-templates.md). |
| `assign_mode`        | string  | `all`   | Assignment mode.                                                                   |
| `start_date`         | date    | `null`  | Start date.                                                                        |
| `start_time`         | time    | `null`  | Start time.                                                                        |
| `department_ids`     | array   | `[]`    | Target departments.                                                                |
| `user_ids`           | array   | `[]`    | Target users.                                                                      |

**Example Request**

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/tasks-2/assignments/quick-assignment', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'title' => 'Quick Safety Check',
        'task_template_id' => 31,
        'assign_mode' => 'any_of',
        'user_ids' => [144]
    ]
]);
```

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 81,
    "title": "Quick Safety Check",
    "task_template_id": 31,
    "quick_assignment": true
  }
}
```

## \[Adm.] Update

**Definition**

<mark style="color:blue;">`PUT`</mark> `/api/administration/tasks-2/assignments/{taskAssignment}`

**Request Keys**

| Key                          | Type     | Description                         |
| ---------------------------- | -------- | ----------------------------------- |
| `taskAssignment`             | integer  | Route parameter. TaskAssignment ID. |
| `title`                      | string   | New assignment title.               |
| `description`                | string   | New description.                    |
| `task_template_id`           | integer  | New template ID.                    |
| `assign_mode`                | string   | New assignment mode.                |
| `start_date`                 | date     | New start date.                     |
| `start_time`                 | time     | New start time.                     |
| `show_before_interval`       | interval | New visibility interval.            |
| `executable_before_interval` | interval | New executable-before interval.     |
| `executable_after_interval`  | interval | New executable-after interval.      |
| `interval`                   | string   | New RRULE.                          |
| `interval_end`               | date     | New recurrence end date.            |
| `active`                     | boolean  | New active state.                   |
| `always_executable`          | boolean  | New always-executable state.        |
| `user_confirmation_required` | boolean  | New confirmation requirement.       |
| `delayed_reason_required`    | boolean  | New delayed-reason requirement.     |
| `deny_reason_required`       | boolean  | New deny-reason requirement.        |
| `reset_allowed`              | boolean  | New reset-allowed state.            |
| `sort_number`                | integer  | New sort number.                    |
| `department_ids`             | array    | Updated target departments.         |
| `user_ids`                   | array    | Updated target users.               |

**Example Request**

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/administration/tasks-2/assignments/80', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'title' => 'Morning Shift (updated)',
        'reset_allowed' => false
    ]
]);
```

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 80,
    "title": "Morning Shift (updated)",
    "reset_allowed": false
  }
}
```

## \[Adm.] Delete

**Definition**

<mark style="color:red;">`DELETE`</mark> `/api/administration/tasks-2/assignments/{taskAssignment}`

**Request Keys**

| Key              | Type    | Default | Description       |
| ---------------- | ------- | ------- | ----------------- |
| `taskAssignment` | integer | -       | TaskAssignment ID |

**Example Request**

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('DELETE', '/api/administration/tasks-2/assignments/80', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

**Example Response**

```json
{
  "status": "success",
  "data": null
}
```
