n8n — Workflow Automation
n8n is an open-source workflow automation platform for building deterministic pipelines and autonomous AI agents. It connects APIs, databases, AI models, and custom code through a visual node-based editor.
Self-hosted or cloud. You own your data, workflows, and execution environment.
Core Concepts
| Concept | What It Is |
|---|---|
| Node | A single operation: API call, data transform, AI model call, conditional check |
| Workflow | A chain of nodes connected by edges. Executes left-to-right. |
| Trigger | The first node — starts the workflow (webhook, schedule, form, chat, manual, error) |
| Item | A single data object flowing through the workflow. Nodes process items one at a time. |
| Credential | Stored API key or auth token. Reusable across workflows. Never hardcoded. |
| Expression | Dynamic value using {{ }} syntax — pulls data from previous nodes |
| Sub-workflow | A reusable workflow called from other workflows |
The 17 Nodes to Master
These nodes cover ~90% of all production workflows:
| # | Node | Purpose | Category |
|---|---|---|---|
| 1 | Webhook | Receive HTTP requests, return responses | Trigger |
| 2 | Schedule | Run on cron (every hour, daily, etc.) | Trigger |
| 3 | HTTP Request | Call any API (GET, POST, PUT, DELETE) | Integration |
| 4 | Set | Create/transform fields, build test data | Data |
| 5 | If | Binary routing (true/false) | Logic |
| 6 | Switch | Multi-path routing (3+ outcomes) | Logic |
| 7 | Loop | Process items in batches | Flow |
| 8 | Split Out | Array to individual items | Data |
| 9 | Aggregate | Individual items to single array | Data |
| 10 | Merge | Combine data from parallel branches | Data |
| 11 | Code | Custom JavaScript/Python | Transform |
| 12 | AI Agent | Autonomous LLM with tools | AI |
| 13 | Chat Model | Direct LLM call (no autonomy) | AI |
| 14 | Execute Sub Workflow | Call reusable sub-workflows | Architecture |
| 15 | Google Sheets | Read/write/update rows | Storage |
| 16 | Pause | Wait for human approval | Control |
| 17 | Error Handler | Catch failures, route to recovery | Reliability |
Conditional Logic
Two outputs: true and false.
Order received → If (total >= $50) → true: Apply discount
→ false: Standard processing
Multiple named outputs for 3+ conditions.
Support ticket → Switch (priority) → low: Queue
→ medium: Assign agent
→ high: Alert team
→ VIP: Direct escalation
Rename Switch outputs from “0, 1, 2” to descriptive labels for readability.
Expressions & Variables
| Mode | Behavior | When |
|---|---|---|
| Fixed | Literal text — hello means “hello” | Static values |
| Expression | Dynamic — {{ $json.name }} pulls data | Always for dynamic data |
// Relative: immediate previous node
{{ $json.email }}
// Absolute: specific node by name (preferred)
{{ $('OpenAI').item.json.message.content }}
Always prefer absolute references ($('NodeName')) — they don’t break when you insert nodes between them.
| Special Variable | Purpose |
|---|---|
$now | Current date/time |
$fromAI("paramName", "desc") | Let AI agent supply a parameter dynamically |
$json | Current item’s data |
$('NodeName').item.json | Specific node’s output |
Workflow vs. Agent — When to Use Which
| Criteria | Workflow | Agent |
|---|---|---|
| Logic | Deterministic, rule-based | Autonomous reasoning |
| Path | Fixed decision tree | Flexible, AI-decided |
| Best for | Data transform, API orchestration | Complex reasoning, tool selection |
| Reliability | Same input = same output | Variable |
| Cost | Low (no LLM calls) | Higher (every decision = LLM call) |
| Debugging | Easy (follow fixed path) | Harder (opaque reasoning) |
Common Workflow Templates
| Template | Pattern | Key Nodes |
|---|---|---|
| AI Inbox Manager | Classify > Route > Respond | Webhook, AI Agent, Switch, Send Email |
| RAG Knowledge Base | Upload > Embed > Store > Query | Schedule, HTTP Request, Embeddings, Vector Store |
| Lead Qualifier | Receive > Research > Score > Route | Webhook, HTTP Request, AI Agent, If |
| Content Pipeline | Research > Draft > Review > Publish | Schedule, AI Agent, Pause (HITL), HTTP Request |
| Multi-Agent System | Orchestrator > Specialists > Merge | AI Agent, Execute Sub Workflow, Merge |