Branches & Loops
Control the flow of your automations with conditional branching and looping.
Branches (Conditional Logic)
IF / Else (Flow Builder)
Add a Branch step to create conditional paths:
Trigger → Fetch Data → Branch
├── IF condition is true → Send Success Email
└── ELSE → Send Failure Alert
Condition operators:
- Equals / Not equals
- Contains / Does not contain
- Greater than / Less than
- Is empty / Is not empty
- Starts with / Ends with
- Matches regex
Example: Route support tickets based on priority:
IF {{trigger.body.priority}} equals "urgent"
→ Post to #urgent-support Slack channel
ELSE
→ Create Jira ticket in backlog
IF Node (Workflow Builder)
The IF node evaluates conditions and routes data to "true" or "false" outputs:
// String comparison
{{ $json.status }} equals "active"
// Numeric comparison
{{ $json.amount }} is greater than 100
// Boolean check
{{ $json.isVerified }} is true
// Regex match
{{ $json.email }} matches regex ".*@company\.com"
Switch Node (Workflow Builder)
Route data to multiple outputs based on a value:
Switch on {{ $json.department }}
├── "sales" → Notify sales team
├── "support" → Create support ticket
├── "billing" → Forward to billing
└── default → Send to general inbox
Merge Node (Workflow Builder)
Combine data from multiple branches back together:
- Append — Combine all items from all inputs
- Keep Key Matches — Inner join on a shared key
- Combine by Position — Match items by their index
- Choose Branch — Select which input to pass through
Loops
Loop Over Items (Workflow Builder)
Process an array of items one at a time:
Trigger → Fetch 100 Contacts → Loop Over Items → Send Personalized Email
Configuration:
- Batch Size — Process N items at a time (default: 1)
- Options — Continue on fail, reset on each item
Looping with Code
For more complex iteration patterns, use the Code node:
const items = $input.all();
const results = [];
for (const item of items) {
// Process each item
const enriched = {
...item.json,
processed: true,
processedAt: new Date().toISOString()
};
results.push({ json: enriched });
}
return results;
Pagination Loops
Fetch data from APIs that return paginated results:
Set page = 1 → HTTP Request (page N) → IF has more pages?
├── Yes → Increment page → Loop back
└── No → Continue with all data
Best Practices
- Keep branches shallow — Deeply nested conditions are hard to maintain. Consider using Switch instead of nested IF/ELSE.
- Use Merge nodes to recombine branches — Don't let branches "hang" without merging.
- Set batch sizes appropriately — Processing 1,000 items one at a time is slow. Use batch sizes of 10–50 for API calls with rate limits.
- Add error handling inside loops — A single failed item shouldn't stop the entire loop.