Chapter 8

Flow Control Nodes

Ch08 Flow Control Nodes

Real workflows are not linear — data needs to take different paths based on conditions, some operations must wait for external events, and some scenarios require iterating over collections. n8n provides a complete set of flow control nodes: IF (conditional branch), Switch (multi-way routing), Loop Over Items (iteration), Wait (pause/resume), and Merge (stream joining). This chapter covers each node in depth through practical scenarios.

IF Node: Conditional Branching

The IF node is the most fundamental flow control node. It evaluates a condition and routes items to one of two outputs: True (condition met) or False (condition not met).

Condition Types

IF supports multiple condition types that can be combined with AND/OR logic:

Example: Route Orders by Amount

{
  "conditions": {
    "conditions": [
      {
        "leftValue": "={{ $json.totalAmount }}",
        "rightValue": 1000,
        "operator": {
          "type": "number",
          "operation": "gte"
        }
      }
    ],
    "combinator": "and"
  }
}

Switch Node: Multi-Way Routing

When routing a field's value to multiple different branches, Switch is cleaner than chaining multiple IF nodes. Each branch is an independent output port.

Example: Route by Order Status

Switch field: {{ $json.status }}
- Output 1: equals "pending"   → Awaiting payment handling
- Output 2: equals "paid"      → Payment confirmed handling
- Output 3: equals "shipped"   → Shipped handling
- Output 4: equals "refunded"  → Refund handling
- Fallback (default)           → Unknown status alert

Switch vs IF: IF is best for simple binary decisions. Switch is best for "one field, multiple enum values" routing. For complex routing involving combinations of multiple fields, use a Code node to implement custom logic.

Loop Over Items Node: Sequential Iteration

Loop Over Items provides explicit loop control over an items array, processing one item at a time. Unlike n8n's default behavior (which processes items concurrently), this node enforces sequential execution.

Common use cases:

Wait Node: Pause and Resume

The Wait node pauses a workflow execution at a specific point, resuming when one of these conditions is met:

Typical Scenario: Human Approval Flow

1. [New order received] → [Send approval notification to Feishu with "Approve" button link]
2.  Wait node (Webhook mode, 24-hour timeout)
3. [Reviewer clicks button] → [Wait node receives callback, workflow resumes]
4. [Process based on approval result (button carries approve/reject parameter)]

The Wait node in Webhook mode generates a callback URL in this format:

https://your-n8n.com/webhook/[execution-id]/[resume-token]

Embed this URL in Feishu card buttons, email links, or share it directly with the reviewer — clicking it automatically resumes the workflow.

Wait Node Configuration (Webhook Mode)

{
  "resume": "webhook",
  "options": {
    "webhookSuffix": "approve-order-{{ $json.orderId }}",
    "responseData": "firstEntryJson",
    "limit": {
      "unit": "hours",
      "value": 24
    }
  }
}

Merge Node: Combine Multiple Input Streams

When a workflow forks and needs to reconverge, use the Merge node. Merge modes:

Example: Parallel API Calls Then Merge

[User profile API] → \
                      Merge (By Key: userId) → [Downstream processing]
[User orders API]  → /

Best practice: Parallelizing independent API calls and merging results dramatically speeds up workflow execution. Don't chain API calls sequentially if they don't depend on each other — run them in parallel and merge at the end.

Complete Example: Order Approval and Routing Workflow

Combining all the above nodes into a complete order processing flow:

  1. Webhook Trigger: Receive new order
  2. IF node: Amount ≥ $5,000 requires manual review?
    • True: Send approval notification → Wait node (wait for reviewer to click approve/reject) → Switch node (approve/reject branch handling)
    • False: Auto-process immediately
  3. Switch node (order type):
    • Domestic order → Call domestic logistics API
    • International order → Call international shipping API
    • Digital product → Send activation code directly
  4. Merge node: Reconverge all branches
  5. HTTP Request: Update order status + send customer notification
Rate this chapter
4.8  / 5  (40 ratings)

💬 Comments