> 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/triggers.md).

# Triggers

## Introduction

`Triggers` are the starting point of an automation workflow. They define when something should happen and belong to a supported resource.

When a trigger matches an event or schedule, it evaluates its associated [Conditions](/api-reference/automation/conditions.md). If the conditions are met, it executes the linked [Actions](/api-reference/automation/actions.md).

Triggers are typically accessed via the `triggers` relation on the targetable entity.

## Model Definition

**Relations**

| Key          | Relation                                             | Type       | Relation Field(s)                  |
| ------------ | ---------------------------------------------------- | ---------- | ---------------------------------- |
| `actions`    | [Action](/api-reference/automation/actions.md)       | Morph Many | -                                  |
| `conditions` | [Condition](/api-reference/automation/conditions.md) | Morph Many | -                                  |
| `targetable` | (Polymorphic)                                        | Morph To   | `targetable_id`, `targetable_type` |

**Targetable Types**

* `action` - Attaches the Trigger to an [Action](/api-reference/automation/actions.md).
* `form` - Attaches the Trigger to a [Form](/api-reference/forms/forms.md).
* `taskTemplate` - Attaches the Trigger to a [TaskTemplate](/api-reference/tasks-2/task-templates.md).

**Capabilities**

* [Translations](/introduction/resource-capabilities/translations.md) - Localizes `title`; examples use `en-US`.

## Create

Create a new `Trigger`.

**Definition**

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

**Request Keys**

| Key                 | Type      | Default         | Description                                                                        |
| ------------------- | --------- | --------------- | ---------------------------------------------------------------------------------- |
| `targetable_type`\* | `string`  | -               | Selects one of the supported [Targetable Types](#targetable-types).                |
| `targetable_id`\*   | `integer` | -               | ID of the targetable entity instance.                                              |
| `lang_id`           | `string`  | system language | Language for translatable Trigger fields. If omitted, the system language is used. |
| `title`\*           | `string`  | -               | Display title of the Trigger.                                                      |
| `allow_parallel`    | `boolean` | `false`         | Whether multiple executions may run in parallel.                                   |
| `active`            | `boolean` | `true`          | Whether the Trigger is active.                                                     |
| `sort_number`       | `integer` | -               | Sort order within the targetable context.                                          |

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/triggers', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'title' => 'On TaskTemplate Event',
        'targetable_type' => 'taskTemplate',
        'targetable_id' => 123,
        'lang_id' => 'en-US',
        'allow_parallel' => false,
        'active' => true,
        'sort_number' => 10
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 1,
    "title": "On TaskTemplate Event",
    "targetable_type": "taskTemplate",
    "targetable_id": 123,
    "lang_id": "en-US",
    "allow_parallel": false,
    "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 `Trigger`.

**Definition**

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

**Route Parameters**

| Parameter | Type      | Description |
| --------- | --------- | ----------- |
| `trigger` | `integer` | Trigger ID. |

**Request Keys**

| Key               | Type      | Default | Description                                                         |
| ----------------- | --------- | ------- | ------------------------------------------------------------------- |
| `targetable_type` | `string`  | -       | Selects one of the supported [Targetable Types](#targetable-types). |
| `targetable_id`   | `integer` | -       | ID of the new targetable entity instance.                           |
| `lang_id`         | `string`  | -       | Updated language for translatable Trigger fields.                   |
| `title`           | `string`  | -       | Updated title of the Trigger.                                       |
| `allow_parallel`  | `boolean` | -       | Updated parallel execution behavior.                                |
| `active`          | `boolean` | -       | Updated active state.                                               |
| `sort_number`     | `integer` | -       | Updated sort order.                                                 |

**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/triggers/1', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'lang_id' => 'en-US',
        'title' => 'Updated Trigger Title',
        'allow_parallel' => true
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 1,
    "title": "Updated Trigger Title",
    "targetable_type": "taskTemplate",
    "targetable_id": 123,
    "lang_id": "en-US",
    "allow_parallel": true,
    "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 a `Trigger`.

**Definition**

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

**Route Parameters**

| Parameter | Type      | Description |
| --------- | --------- | ----------- |
| `trigger` | `integer` | Trigger ID. |

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

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