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

# Conditions

## Introduction

`Conditions` control whether a Trigger's Actions should execute.

A Condition can be attached directly to a Trigger or nested inside a [ConditionGroup](/api-reference/automation/condition-groups.md) to build complex boolean logic.

## Model Definition

**Relations**

| Key          | Relation                                                                                                            | Type     | Relation Field(s)                  |
| ------------ | ------------------------------------------------------------------------------------------------------------------- | -------- | ---------------------------------- |
| `attachable` | [Trigger](/api-reference/automation/triggers.md) or [ConditionGroup](/api-reference/automation/condition-groups.md) | Morph To | `attachable_id`, `attachable_type` |

**Attachable Types**

* `trigger` - Attaches the condition to a [Trigger](/api-reference/automation/triggers.md).
* `conditionGroup` - Nests the condition in a [ConditionGroup](/api-reference/automation/condition-groups.md).
* `formFieldDisplayCondition` - Attaches the condition to a form-field display condition.

**Types**

* `systemVariable` - Compares a resolved [System Variable](/introduction/system-variables.md).
* `formFieldValue` - Compares a form-field value.
* `taskStatus` - Compares a task status.

**Operators**

* `equal` - Matches equal values.
* `not_equal` - Matches unequal values.
* `greater` - Matches a greater value.
* `greater_equal` - Matches an equal or greater value.
* `lower` - Matches a lower value.
* `lower_equal` - Matches an equal or lower value.
* `is_null` - Matches a missing value without requiring `value`.
* `not_null` - Matches a present value without requiring `value`.
* `contains` - Matches when the source contains `value`.
* `not_contains` - Matches when the source does not contain `value`.

## System Variable Handling

For a `systemVariable` condition, `key` must contain a valid [key-only System Variable](/introduction/system-variables.md#key-only-values), such as `system.user.id`. Do not wrap the key in braces or add a formatter.

For every condition type, `value` may contain a validated [rendered template](/introduction/system-variables.md#rendered-templates), such as `User ID: {{ system.user.id }}`. Invalid template syntax and invalid System Variable expressions are rejected during creation and update.

## Create

Create a new `Condition`.

**Definition**

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

**Request Keys**

| Key                 | Type                  | Default | Description                                                                                                      |
| ------------------- | --------------------- | ------- | ---------------------------------------------------------------------------------------------------------------- |
| `attachable_type`\* | `string`              | -       | Selects one of the supported [Attachable Types](#attachable-types).                                              |
| `attachable_id`\*   | `integer`             | -       | ID of the parent attachable entity.                                                                              |
| `type`\*            | `string`              | -       | Selects one of the supported [Types](#types).                                                                    |
| `key`\*             | `string` \| `integer` | -       | Type-specific condition key (e.g. system variable key or form field ID).                                         |
| `operator`\*        | `string`              | -       | Selects one of the supported [Operators](#operators).                                                            |
| `value`             | `string` \| `null`    | -       | Comparison value; supports validated [rendered templates](/introduction/system-variables.md#rendered-templates). |

Keys with `*` are required.

**Behavior**

* `value` is required unless `operator` is `is_null` or `not_null`.
* A `systemVariable` condition requires `key` to use [key-only syntax](/introduction/system-variables.md#key-only-values).

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/conditions', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'attachable_type' => 'trigger',
        'attachable_id' => 42,
        'type' => 'systemVariable',
        'key' => 'system.user.id',
        'operator' => 'equal',
        'value' => '123'
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 1,
    "attachable_type": "trigger",
    "attachable_id": 42,
    "type": "systemVariable",
    "key": "system.user.id",
    "operator": "equal",
    "value": "123",
    "created_at": "2024-01-01 10:00:00",
    "updated_at": "2024-01-01 10:00:00",
    "deleted_at": null
  }
}
```

## Update

Update an existing `Condition`.

**Definition**

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

**Route Parameters**

| Parameter   | Type      | Description   |
| ----------- | --------- | ------------- |
| `condition` | `integer` | Condition ID. |

**Request Keys**

| Key               | Type                  | Default | Description                                                                                                              |
| ----------------- | --------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------ |
| `attachable_type` | `string`              | -       | Selects one of the supported [Attachable Types](#attachable-types).                                                      |
| `attachable_id`   | `integer`             | -       | New parent entity ID.                                                                                                    |
| `type`            | `string`              | -       | Selects one of the supported [Types](#types).                                                                            |
| `key`             | `string` \| `integer` | -       | Updated type-specific condition key.                                                                                     |
| `operator`        | `string`              | -       | Selects one of the supported [Operators](#operators).                                                                    |
| `value`           | `string` \| `null`    | -       | Updated comparison value; supports validated [rendered templates](/introduction/system-variables.md#rendered-templates). |

**Behavior**

* Only submitted keys are updated.
* The resulting condition must keep a valid type-specific key, operator, and value combination. A `systemVariable` key uses [key-only syntax](/introduction/system-variables.md#key-only-values).

**Example Request**

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

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/conditions/1', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'key' => 'system.user.email',
        'operator' => 'not_equal',
        'value' => 'old@example.com'
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 1,
    "attachable_type": "trigger",
    "attachable_id": 42,
    "type": "systemVariable",
    "key": "system.user.email",
    "operator": "not_equal",
    "value": "old@example.com",
    "created_at": "2024-01-01 10:00:00",
    "updated_at": "2024-01-02 11:00:00",
    "deleted_at": null
  }
}
```

## Delete

Delete a `Condition`.

**Definition**

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

**Route Parameters**

| Parameter   | Type      | Description   |
| ----------- | --------- | ------------- |
| `condition` | `integer` | Condition ID. |

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

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