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

# Actions

## Introduction

`Actions` define what should happen after a [Trigger](/api-reference/automation/triggers.md) has been evaluated.

An Action belongs to a [Trigger](/api-reference/automation/triggers.md) and executes logic based on its documented [Action Type](#action-types) and `config`.

Actions can be targeted to users/departments and can be overwritten in specific contexts via [ActionOverwrites](/api-reference/automation/action-overwrites.md).

Rich-text values in type-specific `config.text`, `config.body`, and `config.description` keys use the shared [Rich Text](/introduction/rich-text.md) HTML format.

System Variable-enabled text fields in `createInfoboardPost`, `createTaskAssignment`, and `notify` configs must contain valid [rendered templates](/introduction/system-variables.md#rendered-templates). Their `computed_targetables_system_variable` config uses [key-only syntax](/introduction/system-variables.md#key-only-values).

## Model Definition

**Relations**

| Key           | Relation                                         | Type            | Relation Field(s)         |
| ------------- | ------------------------------------------------ | --------------- | ------------------------- |
| `trigger`     | [Trigger](/api-reference/automation/triggers.md) | Belongs To      | `trigger_id`              |
| `users`       | User                                             | Belongs To Many | Pivot `user_action`       |
| `departments` | Department                                       | Belongs To Many | Pivot `department_action` |

**Action Types**

* `createInfoboardPost` - Creates an [InfoboardPost](/api-reference/infoboard/infoboard-posts.md).
* [`createTaskAssignment`](/api-reference/automation/action-types/create-task-assignment.md) - Creates a [TaskAssignment](/api-reference/tasks-2/task-assignments.md).
* [`notify`](/api-reference/automation/action-types/notify.md) - Sends a notification.
* [`webhook`](/api-reference/automation/action-types/webhook.md) - Dispatches an outbound webhook request.

**Capabilities**

* [Targetables](/introduction/resource-capabilities/targetables.md) - `assign_mode`, `user_ids`, and `department_ids` select the recipients used by the action type.
* [Translations](/introduction/resource-capabilities/translations.md) - Localizes `title`; examples use `en-US`.

## Create

Create a new `Action`.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/actions`

**Request Keys**

| Key                        | Type               | Default                               | Description                                                                                                                                                  |
| -------------------------- | ------------------ | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `title`\*                  | `string`           | -                                     | Action title.                                                                                                                                                |
| `trigger_id`\*             | `integer`          | -                                     | ID of the related [Trigger](/api-reference/automation/triggers.md).                                                                                          |
| `lang_id`                  | `string`           | system language                       | Language for translatable Action fields. If omitted, the system language is used.                                                                            |
| `type`\*                   | `string`           | -                                     | Selects one of the supported [Action Types](#action-types).                                                                                                  |
| `on_condition`             | `boolean`          | `true`                                | Whether the Action runs on fulfilled (`true`) or failed (`false`) condition branch.                                                                          |
| `tries`                    | `integer`          | `1`                                   | Number of retry attempts for execution.                                                                                                                      |
| `timeout`                  | `integer`          | `120`                                 | Timeout in seconds for execution.                                                                                                                            |
| `config`\*                 | `object`           | default config by `type`              | Type-specific configuration payload.                                                                                                                         |
| `assign_mode`              | `string`           | `none`                                | Targeting strategy selected from the shared [Assignment Modes](/introduction/assignment-and-targeting.md#assignment-modes).                                  |
| `computed_targetable_type` | `string` \| `null` | `null`                                | Optional [Computed Targetable Type](/introduction/assignment-and-targeting.md#dynamic-assignment); the supported subset depends on the selected Action type. |
| `active`                   | `boolean`          | `true`                                | Whether the Action is active.                                                                                                                                |
| `sort_number`              | `integer`          | -                                     | Sort order inside the Trigger branch.                                                                                                                        |
| `user_ids`                 | `integer[]`        | `[]` (for assign mode `none/all/...`) | Explicit target users.                                                                                                                                       |
| `department_ids`           | `integer[]`        | `[]` (for assign mode `none/all/...`) | Explicit target departments.                                                                                                                                 |

Keys with `*` are required.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/actions', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'title' => 'Send Webhook',
        'trigger_id' => 42,
        'lang_id' => 'en-US',
        'type' => 'webhook',
        'config' => [
            'url' => 'https://httpbin.org/post',
            'method' => 'POST',
            'headers' => [],
            'auth' => null,
        ],
        'on_condition' => true,
        'tries' => 1,
        'timeout' => 120,
        'assign_mode' => 'none',
        'active' => true,
        'sort_number' => 10,
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 1,
    "title": "Send Webhook",
    "trigger_id": 42,
    "lang_id": "en-US",
    "type": "webhook",
    "on_condition": true,
    "tries": 1,
    "timeout": 120,
    "config": {
      "url": "https://httpbin.org/post",
      "method": "POST",
      "headers": [],
      "auth": null
    },
    "assign_mode": "none",
    "computed_targetable_type": null,
    "active": true,
    "sort_number": 10,
    "created_at": "2024-01-01 10:00:00",
    "updated_at": "2024-01-01 10:00:00",
    "deleted_at": null
  }
}
```

## Update

Update an existing `Action`.

**Definition**

<mark style="color:blue;">`PUT`</mark> `/api/actions/{action}`

**Route Parameters**

| Parameter | Type      | Description |
| --------- | --------- | ----------- |
| `action`  | `integer` | Action ID.  |

**Request Keys**

| Key                        | Type               | Default                                                              | Description                                                                                                                                                 |
| -------------------------- | ------------------ | -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `title`                    | `string`           | -                                                                    | Updated Action title.                                                                                                                                       |
| `trigger_id`               | `integer`          | -                                                                    | New Trigger ID.                                                                                                                                             |
| `lang_id`                  | `string`           | -                                                                    | Updated language for translatable fields.                                                                                                                   |
| `type`                     | `string`           | current Action type                                                  | Selects one of the supported [Action Types](#action-types).                                                                                                 |
| `on_condition`             | `boolean`          | -                                                                    | Updated branch behavior.                                                                                                                                    |
| `tries`                    | `integer`          | -                                                                    | Updated retry attempts.                                                                                                                                     |
| `timeout`                  | `integer`          | -                                                                    | Updated timeout in seconds.                                                                                                                                 |
| `config`                   | `object`           | default config by `type` (only if type changed and `config` omitted) | Updated type-specific config payload.                                                                                                                       |
| `assign_mode`              | `string`           | current assign mode                                                  | Updated targeting strategy selected from the shared [Assignment Modes](/introduction/assignment-and-targeting.md#assignment-modes).                         |
| `computed_targetable_type` | `string` \| `null` | -                                                                    | Updated [Computed Targetable Type](/introduction/assignment-and-targeting.md#dynamic-assignment); the supported subset depends on the selected Action type. |
| `active`                   | `boolean`          | -                                                                    | Updated active state.                                                                                                                                       |
| `sort_number`              | `integer`          | -                                                                    | Updated sort order.                                                                                                                                         |
| `user_ids`                 | `integer[]`        | `[]` (for assign mode `none/all/...`)                                | Updated target users.                                                                                                                                       |
| `department_ids`           | `integer[]`        | `[]` (for assign mode `none/all/...`)                                | Updated target departments.                                                                                                                                 |

**Behavior**

Only submitted keys are updated.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/actions/1', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'lang_id' => 'en-US',
        'title' => 'Send Notify',
        'type' => 'notify',
        'config' => [
            'title' => 'Notification Title',
            'body' => '<p>Notification body.</p>',
            'exclude_executing_targetable' => false,
            'send_mail' => false,
            'plain_email' => false
        ]
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 1,
    "title": "Send Notify",
    "trigger_id": 42,
    "lang_id": "en-US",
    "type": "notify",
    "on_condition": true,
    "tries": 1,
    "timeout": 120,
    "config": {
      "title": "Notification Title",
      "body": "<p>Notification body.</p>",
      "exclude_executing_targetable": false,
      "send_mail": false,
      "plain_email": false
    },
    "assign_mode": "none",
    "computed_targetable_type": null,
    "active": true,
    "sort_number": 10,
    "created_at": "2024-01-01 10:00:00",
    "updated_at": "2024-01-02 11:00:00",
    "deleted_at": null
  }
}
```

## Delete

Delete an `Action`.

**Definition**

<mark style="color:red;">`DELETE`</mark> `/api/actions/{action}`

**Route Parameters**

| Parameter | Type      | Description |
| --------- | --------- | ----------- |
| `action`  | `integer` | Action ID.  |

**Example Request**

{% tabs %}
{% tab title="PHP" %}

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

{% endtab %}
{% endtabs %}

**Example Response**

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