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:
- String: equals, not equals, contains, does not contain, starts/ends with, regex match
- Number: equals, not equals, greater than, less than, gte, lte
- Boolean: is true / is false
- DateTime: before, after, equals
- Array: contains, does not contain an element
Example: Route Orders by Amount
{
"conditions": {
"conditions": [
{
"leftValue": "={{ $json.totalAmount }}",
"rightValue": 1000,
"operator": {
"type": "number",
"operation": "gte"
}
}
],
"combinator": "and"
}
}
- True branch: High-value orders (≥ $1000) → Route to senior sales team
- False branch: Standard orders → Normal processing queue
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:
- Send personalized emails one at a time (wait for each to complete before the next)
- Call APIs serially (avoid concurrent requests exceeding rate limits)
- Write to a database maintaining insertion order
Wait Node: Pause and Resume
The Wait node pauses a workflow execution at a specific point, resuming when one of these conditions is met:
- Time-based: Wait a fixed duration (seconds/minutes/hours), or until a specific datetime
- Webhook callback: Pause and generate a unique callback URL; workflow resumes when a POST arrives
- Form submission: Pause and generate a form URL; workflow resumes when a user submits it
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:
- Append: Combine all input items into one items array (earlier inputs first)
- Merge By Index: Align by position — item[0] from input 1 merges with item[0] from input 2
- Merge By Key: Match items across inputs by a shared field value (like SQL JOIN)
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:
- Webhook Trigger: Receive new order
- 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
- Switch node (order type):
- Domestic order → Call domestic logistics API
- International order → Call international shipping API
- Digital product → Send activation code directly
- Merge node: Reconverge all branches
- HTTP Request: Update order status + send customer notification