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

# ConditionGroups

## Introduction

`ConditionGroups` allow you to combine multiple Conditions and nested groups with boolean expressions.

They are used to build logic trees such as:

* `A AND B`
* `A OR (B AND C)`

A ConditionGroup can be attached to a [Trigger](/api-reference/automation/triggers.md) or another `ConditionGroup`.

## Model Definition

**Relations**

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

**Attachable Types**

* `trigger` - Attaches the group to a [Trigger](/api-reference/automation/triggers.md).
* `conditionGroup` - Nests the group below another Condition Group.
* `formFieldDisplayCondition` - Attaches the group to a form-field display condition.

**Expressions**

* `AND` - Requires every child condition or group to match.
* `OR` - Requires at least one child condition or group to match.

## Create

Create a new `ConditionGroup`.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/condition-groups`

**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.                                 |
| `expression`\*      | `string`  | -       | Selects one of the supported [Expressions](#expressions).           |

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/condition-groups', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'attachable_type' => 'trigger',
        'attachable_id' => 42,
        'expression' => 'AND'
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 1,
    "attachable_type": "trigger",
    "attachable_id": 42,
    "expression": "AND",
    "created_at": "2024-01-01 10:00:00",
    "updated_at": "2024-01-01 10:00:00",
    "deleted_at": null
  }
}
```

## Update

Update an existing `ConditionGroup`.

**Definition**

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

**Route Parameters**

| Parameter        | Type      | Description        |
| ---------------- | --------- | ------------------ |
| `conditionGroup` | `integer` | ConditionGroup 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.                                               |
| `expression`      | `string`  | -       | Selects one of the supported [Expressions](#expressions).           |

**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/condition-groups/1', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'expression' => 'OR'
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 1,
    "attachable_type": "trigger",
    "attachable_id": 42,
    "expression": "OR",
    "created_at": "2024-01-01 10:00:00",
    "updated_at": "2024-01-02 11:00:00",
    "deleted_at": null
  }
}
```

## Delete

Delete a `ConditionGroup`.

**Definition**

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

**Route Parameters**

| Parameter        | Type      | Description        |
| ---------------- | --------- | ------------------ |
| `conditionGroup` | `integer` | ConditionGroup ID. |

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

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