n8n Interface và First Workflow
Thực hành là cách học tốt nhất! Bài này sẽ guide bạn qua giao diện n8n và tạo workflow hoàn chỉnh đầu tiên.
🎯 Mục tiêu
- Nắm vững giao diện n8n
- Hiểu các loại nodes cơ bản
- Tạo workflow đầu tiên
- Debug và test workflow
1. Cài Đặt n8n
Option 1: n8n Cloud (Recommended cho beginners)
- Truy cập n8n.io
- Sign up free trial
- Bắt đầu ngay, không cần setup
Option 2: Self-hosted với Docker
1# Chạy n8n với Docker (1 command)2docker run -it --rm \3 --name n8n \4 -p 5678:5678 \5 -v n8n_data:/home/node/.n8n \6 n8nio/n8n7 8# Truy cập: http://localhost:5678Option 3: npm (Node.js required)
1npm install n8n -g2n8n start3 4# Truy cập: http://localhost:56782. Giao Diện n8n
2.1. Overview
1┌─────────────────────────────────────────────────────────────┐2│ [Logo] Workflows ▼ Credentials Executions ⚙️ │ ← Top Bar3├─────────────────────────────────────────────────────────────┤4│ │5│ │6│ CANVAS AREA │ ← Drag & Drop7│ │ Nodes Here8│ [Trigger] ────► [Node] ────► [Node] │9│ │10│ │11├─────────────────────────────────────────────────────────────┤12│ [+] Add Node [▶] Execute [💾] Save [⚡] Active │ ← Bottom Bar13└─────────────────────────────────────────────────────────────┘2.2. Key Areas
| Area | Function |
|---|---|
| Canvas | Nơi thiết kế workflow, drag-drop nodes |
| Node Panel | Click [+] để thêm nodes mới |
| Node Settings | Click node để configure |
| Execution Log | Xem history và debug |
| Credentials | Quản lý API keys, logins |
2.3. Shortcuts
| Shortcut | Action |
|---|---|
Space | Open node search |
Ctrl/Cmd + S | Save workflow |
Ctrl/Cmd + E | Execute workflow |
Delete | Remove selected node |
Ctrl/Cmd + C/V | Copy/Paste nodes |
3. Node Types
3.1. Trigger Nodes
Khởi động workflow khi có event.
| Node | Trigger when |
|---|---|
| Manual Trigger | Click Execute (testing) |
| Schedule Trigger | Cron/interval time |
| Webhook | HTTP request received |
| Email Trigger (IMAP) | New email arrives |
| App Triggers | Google Forms, Slack, etc. |
3.2. Action Nodes (Apps)
Tương tác với external services.
1Popular integrations:2├── Google (Sheets, Drive, Gmail, Calendar)3├── Communication (Slack, Discord, Telegram)4├── CRM (HubSpot, Salesforce, Airtable)5├── Social (Twitter, LinkedIn, Facebook)6└── Others (400+ apps)3.3. Logic Nodes
Control flow của data.
| Node | Function |
|---|---|
| IF | Branch based on condition |
| Switch | Multiple branches |
| Merge | Combine data streams |
| Split In Batches | Process in chunks |
| Wait | Delay execution |
3.4. Data Nodes
Transform và manipulate data.
| Node | Function |
|---|---|
| Set | Create/modify fields |
| Code | Custom JavaScript/Python |
| HTTP Request | Call any API |
| HTML Extract | Scrape web pages |
| Date & Time | Format dates |
4. Hands-on: First Workflow
Workflow: Automated Daily Quote
Mỗi ngày lấy quote inspirational và gửi đến email/Slack.
Step 1: Create New Workflow
- Click "New Workflow"
- Đặt tên: "Daily Inspiration Quote"
Step 2: Add Schedule Trigger
- Press
Spacehoặc click [+] - Search "Schedule"
- Add Schedule Trigger
- Configure:
- Trigger Interval: Every Day
- Hour: 8
- Minute: 0
1┌─────────────────┐2│ Schedule Trigger│3│ Every day 8:00 │4└────────┬────────┘5 │6 ▼Step 3: Add HTTP Request Node
- Click [+] → Search "HTTP Request"
- Connect từ Schedule Trigger
- Configure:
1Method: GET2URL: https://api.quotable.io/random3 4Options:5- Response Format: JSONTest output:
1{2 "content": "The only way to do great work is to love what you do.",3 "author": "Steve Jobs"4}Step 4: Add Set Node (Format Message)
- Add Set node
- Configure fields:
1Mode: Manual2 3Add Field:4- Name: message5- Value: "💡 Quote of the Day\n\n{{ $json.content }}\n\n— {{ $json.author }}"Step 5: Add Email/Slack Node
Option A: Gmail
To: your@email.com
Subject: Daily Inspiration Quote
Message: Use expression $json.message
Option B: Slack
Channel: #general
Message: Use expression $json.message
Final Workflow
1┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐2│ Schedule │────►│ HTTP Request │────►│ Set │────►│ Gmail │3│ (8 AM daily)│ │(Get quote API)│ │(Format msg) │ │(Send email) │4└──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘Step 6: Test & Activate
- Click Execute Workflow để test
- Check output của mỗi node
- Click Active toggle để enable
5. Working with Data
5.1. Accessing Data
1// Previous node output2{{ $json.fieldName }}34// Specific node by name5{{ $node["HTTP Request"].json.content }}67// All items8{{ $items() }}910// Current item index11{{ $itemIndex }}5.2. Expressions Panel
Click ⚡ icon trong field để mở Expression Editor:
Expression Editor preview:
- Input:
$json.content - Output: "The only way to do great work..." └─────────────────────────────────────────┘
1### 5.3. Common Expressions2 3```javascript4// String operations5{{ $json.name.toUpperCase() }}6{{ $json.text.substring(0, 100) }}7 8// Date formatting9{{ $now.format('YYYY-MM-DD') }}10{{ $now.minus(1, 'day').toISO() }}11 12// Conditionals13{{ $json.score >= 50 ? "Pass" : "Fail" }}14 15// Array operations16{{ $json.items.length }}17{{ $json.tags.join(", ") }}18 19// Math20{{ $json.price * 1.1 }} // Add 10%21{{ Math.round($json.value) }}6. Error Handling
6.1. Common Errors
| Error | Cause | Solution |
|---|---|---|
| Connection failed | Bad credentials | Check API keys |
| 404 Not Found | Wrong URL | Verify endpoint |
| 401 Unauthorized | Auth missing | Add credentials |
| Timeout | Slow API | Increase timeout |
| Invalid expression | Syntax error | Check expression syntax |
6.2. Debug Tips
- Execute single node: Click node → Execute Node
- Check output: Click node → Output tab
- View execution log: Left panel → Executions
- Console log: Use Code node với
console.log()
6.3. Error Workflow
1Main Workflow2 │3 ├── Success → Continue4 │5 └── Error → Error Workflow6 │7 ├── Log to Sheet8 ├── Send alert9 └── Retry logic7. Best Practices
7.1. Naming Conventions
1❌ Bad:2HTTP Request, HTTP Request 1, HTTP Request 23 4✅ Good:5Get Quote API, Send to Slack, Save to Sheet7.2. Organize Large Workflows
1Main Workflow2 │3 ├── Sub-workflow: Data Collection4 │5 ├── Sub-workflow: Processing6 │7 └── Sub-workflow: Distribution7.3. Use Sticky Notes
Add notes trong canvas để document workflow logic.
7.4. Version Control
- Export workflows as JSON
- Store in Git repository
- Track changes over time
8. Practice Exercise
Challenge: Build a Weather Alert System
Requirements:
- Schedule: Run at 6 AM daily
- Get weather data from API:
https://api.open-meteo.com/v1/forecast?latitude=21.03&longitude=105.85&daily=precipitation_probability_max - IF rain probability exceeds 60%, send notification
- Message format: "☔ Rain alert! [probability]% chance of rain today"
Hints:
- Use IF node với condition:
{{ $json.daily.precipitation_probability_max[0] }} greater than 60 - Extract probability:
{{ $json.daily.precipitation_probability_max[0] }}
📝 Quiz
-
Node nào bắt đầu workflow?
- Action node
- Trigger node
- Logic node
- Data node
-
Cách access data từ node trước?
-
$previous.data -
{{ $json.fieldName }} -
node.output -
getData()
-
-
IF node dùng để làm gì?
- Chạy code custom
- Call API
- Branch workflow dựa trên condition
- Format data
-
Cách test workflow?
- Click Execute Workflow
- Chỉ có thể test sau khi Active
- Không thể test, phải đợi trigger
- Export và import lại
🎯 Key Takeaways
- Canvas là nơi thiết kế visual workflows
- Trigger → Nodes → Output là basic flow
- Expressions (
{{ }}) để access và transform data - Test often - Execute từng node để debug
- Name clearly - Giúp maintain workflow dễ hơn
🚀 Bài tiếp theo
Google Workspace Integration - Kết nối n8n với Google Sheets, Gmail, Drive!
