> ## Documentation Index
> Fetch the complete documentation index at: https://docs.b3os.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Condition (If / Else)

Branch your workflow based on a condition. If the condition is true, the 'then' path runs; otherwise the 'else' path runs. Supports comparison and membership checks.

Logic action Logic

Branch your workflow based on a condition. If the condition is true, the 'then' path runs; otherwise the 'else' path runs. Supports comparison and membership checks.


## At a Glance

| Field | Value |
| --- | --- |
| Action ID | `if` |
| Category | Logic |
| Connector | Not required |
| Requires gas | No |
| Funds movement | None declared |
| Tags | `logic`, `conditional`, `branching`, `control-flow` |

## Payload Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `condition` | `object` | Yes | Condition DSL. Top-level must be $and or $or. Inside arrays: comparison format &#123; "&#123;&#123;left&#125;&#125;": &#123; "$op": right &#125; &#125; where $op is $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin. Left operand \(key\) can be a template variable like &#123;&#123;node.result.field&#125;&#125; or literal. Right operand \(value\) can be number, string, template variable, or array \(for $in/$nin\). |

## Result Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `branch` | `string` | Yes | Which branch to take |

## Examples

**Workflow node**

```json
{
  "type": "if",
  "payload": {
    "condition": {
      "$and": [
        {
          "{{root.result.price}}": {
            "$gt": 1000
          }
        }
      ]
    }
  },
  "children": []
}
```
  **Test with API**

```bash
curl -X POST "https://api.b3os.org/v1/actions/if/test" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "condition": {
      "$and": [
        {
          "{{root.result.price}}": {
            "$gt": 1000
          }
        }
      ]
    }
  }
}'
```

**Use expressions for dynamic values**

Payload fields can use workflow expressions such as `{{$trigger.body.amount}}`, `{{$nodes.fetch.result.price}}`, and `{{$props.asset}}` when the value should come from a trigger, prior node, or reusable workflow prop.