n8n Workflow Management
Comprehensive workflow automation management for n8n platform with creation, testing, execution monitoring, and performance optimization capabilities.
⚠️ CRITICAL: Workflow Creation Rules
When creating n8n workflows, ALWAYS:
- 1. ✅ Generate COMPLETE workflows with all functional nodes
- ✅ Include actual HTTP Request nodes for API calls (ImageFX, Gemini, Veo, Suno, etc.)
- ✅ Add Code nodes for data transformation and logic
- ✅ Create proper connections between all nodes
- ✅ Use real node types (n8n-nodes-base.httpRequest, n8n-nodes-base.code, n8n-nodes-base.set)
NEVER:
- - ❌ Create "Setup Instructions" placeholder nodes
- ❌ Generate workflows with only TODO comments
- ❌ Make incomplete workflows requiring manual node addition
- ❌ Use text-only nodes as substitutes for real functionality
Example GOOD workflow:
CODEBLOCK0
Example BAD workflow:
CODEBLOCK1
Always build the complete, functional workflow with all necessary nodes configured and connected.
Setup
Required environment variables:
- -
N8N_API_KEY — Your n8n API key (Settings → API in the n8n UI) - INLINECODE1 — Your n8n instance URL
Configure credentials via OpenClaw settings:
Add to ~/.config/openclaw/settings.json:
CODEBLOCK2
Or set per-session (do not persist secrets in shell rc files):
CODEBLOCK3
Verify connection:
CODEBLOCK4
Security note: Never store API keys in plaintext shell config files (~/.bashrc, ~/.zshrc). Use the OpenClaw settings file or a secure secret manager.
Quick Reference
Workflow Management
List Workflows
CODEBLOCK5
Get Workflow Details
CODEBLOCK6
Create Workflows
CODEBLOCK7
Activate/Deactivate
CODEBLOCK8
Testing & Validation
Validate Workflow Structure
CODEBLOCK9
Dry Run Testing
CODEBLOCK10
Test Suite
CODEBLOCK11
Execution Monitoring
List Executions
CODEBLOCK12
Get Execution Details
CODEBLOCK13
Manual Execution
CODEBLOCK14
Performance Optimization
Analyze Performance
CODEBLOCK15
Get Optimization Suggestions
CODEBLOCK16
Generate Optimization Report
CODEBLOCK17
Get Workflow Statistics
CODEBLOCK18
Python API
Basic Usage
CODEBLOCK19
Validation & Testing
CODEBLOCK20
Performance Optimization
CODEBLOCK21
Common Workflows
1. Validate and Test Workflow
CODEBLOCK22
2. Debug Failed Workflow
CODEBLOCK23
3. Optimize Workflow Performance
CODEBLOCK24
4. Monitor Workflow Health
CODEBLOCK25
Validation Checks
The testing module performs comprehensive validation:
Structure Validation
- - ✓ Required fields present (nodes, connections)
- ✓ All nodes have names and types
- ✓ Connection targets exist
- ✓ No disconnected nodes (warning)
Configuration Validation
- - ✓ Nodes requiring credentials are configured
- ✓ Required parameters are set
- ✓ HTTP nodes have URLs
- ✓ Webhook nodes have paths
- ✓ Email nodes have content
Flow Validation
- - ✓ Workflow has trigger nodes
- ✓ Proper execution flow
- ✓ No circular dependencies
- ✓ End nodes identified
Optimization Analysis
The optimizer analyzes multiple dimensions:
Execution Metrics
- - Total executions
- Success/failure rates
- Health status (excellent/good/fair/poor)
- Error patterns
Performance Metrics
- - Node count and complexity
- Connection patterns
- Expensive operations (API calls, database queries)
- Parallel execution opportunities
Bottleneck Detection
- - Sequential expensive operations
- High failure rates
- Missing error handling
- Rate limit issues
Optimization Opportunities
- - Parallel Execution: Identify nodes that can run concurrently
- Caching: Suggest caching for repeated API calls
- Batch Processing: Recommend batching for large datasets
- Error Handling: Add error recovery mechanisms
- Complexity Reduction: Split complex workflows
- Timeout Settings: Configure execution limits
Performance Scoring
Workflows receive a performance score (0-100) based on:
- - Success Rate: Higher is better (50% weight)
- Complexity: Lower is better (30% weight)
- Bottlenecks: Fewer is better (critical: -20, high: -10, medium: -5)
- Optimizations: Implemented best practices (+5 each)
Score interpretation:
- - 90-100: Excellent - Well-optimized
- 70-89: Good - Minor improvements possible
- 50-69: Fair - Optimization recommended
- 0-49: Poor - Significant issues
Best Practices
Development
- 1. Plan Structure: Design workflow nodes and connections before building
- Validate First: Always validate before deployment
- Test Thoroughly: Use dry-run with multiple test cases
- Error Handling: Add error nodes for reliability
- Documentation: Comment complex logic in Code nodes
Testing
- 1. Sample Data: Create realistic test data files
- Edge Cases: Test boundary conditions and errors
- Incremental: Test each node addition
- Regression: Retest after changes
- Production-like: Use staging environment that mirrors production
Deployment
- 1. Inactive First: Deploy workflows in inactive state
- Gradual Rollout: Test with limited traffic initially
- Monitor Closely: Watch first executions carefully
- Quick Rollback: Be ready to deactivate if issues arise
- Document Changes: Keep changelog of modifications
Optimization
- 1. Baseline Metrics: Capture performance before changes
- One Change at a Time: Isolate optimization impacts
- Measure Results: Compare before/after metrics
- Regular Reviews: Schedule monthly optimization reviews
- Cost Awareness: Monitor API usage and execution costs
Maintenance
- 1. Health Checks: Weekly execution statistics review
- Error Analysis: Investigate failure patterns
- Performance Monitoring: Track execution times
- Credential Rotation: Update credentials regularly
- Cleanup: Archive or delete unused workflows
Troubleshooting
Authentication Error
Error: N8N_API_KEY not found in environment
Solution: Set environment variable:
CODEBLOCK27
Connection Error
Error: HTTP 401: Unauthorized
Solution:
- 1. Verify API key is correct
- Check N8NBASEURL is set correctly
- Confirm API access is enabled in n8n
Validation Errors
Validation failed: Node missing 'name' field
Solution: Check workflow JSON structure, ensure all required fields present
Execution Timeout
Status: timeout - Execution did not complete
Solution:
- 1. Check workflow for infinite loops
- Reduce dataset size for testing
- Optimize expensive operations
- Set execution timeout in workflow settings
Rate Limiting
Error: HTTP 429: Too Many Requests
Solution:
- 1. Add Wait nodes between API calls
- Implement exponential backoff
- Use batch processing
- Check API rate limits
Missing Credentials
Warning: Node 'HTTP_Request' may require credentials
Solution:
- 1. Configure credentials in n8n UI
- Assign credentials to node
- Test connection before activating
File Structure
CODEBLOCK33
API Reference
For detailed n8n REST API documentation, see references/api.md or visit:
https://docs.n8n.io/api/
Support
Documentation:
- - n8n Official Docs: https://docs.n8n.io
- n8n Community Forum: https://community.n8n.io
- n8n API Reference: https://docs.n8n.io/api/
Debugging:
- 1. Use validation: INLINECODE5
- Check execution logs: INLINECODE6
- Review optimization report: INLINECODE7
- Test with dry-run: INLINECODE8
n8n 工作流管理
为 n8n 平台提供全面的工作流自动化管理,包括创建、测试、执行监控和性能优化能力。
⚠️ 关键:工作流创建规则
创建 n8n 工作流时,始终:
- 1. ✅ 生成完整的工作流,包含所有功能节点
- ✅ 包含实际的 HTTP 请求节点,用于 API 调用(ImageFX、Gemini、Veo、Suno 等)
- ✅ 添加代码节点,用于数据转换和逻辑处理
- ✅ 在所有节点之间创建正确的连接
- ✅ 使用真实的节点类型(n8n-nodes-base.httpRequest、n8n-nodes-base.code、n8n-nodes-base.set)
切勿:
- - ❌ 创建设置说明占位节点
- ❌ 生成仅包含 TODO 注释的工作流
- ❌ 创建需要手动添加节点的不完整工作流
- ❌ 使用纯文本节点替代实际功能
良好工作流示例:
手动触发 → 设置配置 → HTTP 请求(API 调用)→ 代码(解析)→ 响应
不良工作流示例:
手动触发 → 代码(在此添加 HTTP 节点,配置 API...)
始终构建完整、功能齐全的工作流,配置并连接所有必要节点。
设置
所需环境变量:
- - N8NAPIKEY — 您的 n8n API 密钥(n8n 界面中的设置 → API)
- N8NBASEURL — 您的 n8n 实例 URL
通过 OpenClaw 设置配置凭据:
添加到 ~/.config/openclaw/settings.json:
json
{
skills: {
n8n: {
env: {
N8NAPIKEY: your-api-key-here,
N8NBASEURL: your-n8n-url-here
}
}
}
}
或按会话设置(不要将密钥持久化存储在 shell rc 文件中):
bash
export N8NAPIKEY=your-api-key-here
export N8NBASEURL=your-n8n-url-here
验证连接:
bash
python3 scripts/n8n_api.py list-workflows --pretty
安全提示: 切勿将 API 密钥以明文形式存储在 shell 配置文件(~/.bashrc、~/.zshrc)中。请使用 OpenClaw 设置文件或安全的密钥管理器。
快速参考
工作流管理
列出工作流
bash
python3 scripts/n8n_api.py list-workflows --pretty
python3 scripts/n8n_api.py list-workflows --active true --pretty
获取工作流详情
bash
python3 scripts/n8n_api.py get-workflow --id
--pretty
创建工作流
bash
从 JSON 文件创建
python3 scripts/n8n_api.py create --from-file workflow.json
激活/停用
bash
python3 scripts/n8n_api.py activate --id
python3 scripts/n8n_api.py deactivate --id
测试与验证
验证工作流结构
bash
验证现有工作流
python3 scripts/n8n_tester.py validate --id
从文件验证
python3 scripts/n8n_tester.py validate --file workflow.json --pretty
生成验证报告
python3 scripts/n8n_tester.py report --id
试运行测试
bash
使用数据测试
python3 scripts/n8n_tester.py dry-run --id --data {email: test@example.com}
使用数据文件测试
python3 scripts/n8n_tester.py dry-run --id --data-file test-data.json
完整测试报告(验证 + 试运行)
python3 scripts/n8n_tester.py dry-run --id --data-file test.json --report
测试套件
bash
运行多个测试用例
python3 scripts/n8n_tester.py test-suite --id --test-suite test-cases.json
执行监控
列出执行记录
bash
最近的执行记录(所有工作流)
python3 scripts/n8n_api.py list-executions --limit 10 --pretty
特定工作流的执行记录
python3 scripts/n8n_api.py list-executions --id --limit 20 --pretty
获取执行详情
bash
python3 scripts/n8n_api.py get-execution --id --pretty
手动执行
bash
触发工作流
python3 scripts/n8n_api.py execute --id
带数据执行
python3 scripts/n8n_api.py execute --id --data {key: value}
性能优化
分析性能
bash
完整性能分析
python3 scripts/n8n_optimizer.py analyze --id --pretty
分析特定时间段
python3 scripts/n8n_optimizer.py analyze --id --days 30 --pretty
获取优化建议
bash
按优先级排序的建议
python3 scripts/n8n_optimizer.py suggest --id --pretty
生成优化报告
bash
包含指标、瓶颈和建议的可读报告
python3 scripts/n8n_optimizer.py report --id
获取工作流统计信息
bash
执行统计
python3 scripts/n8n_api.py stats --id --days 7 --pretty
Python API
基本用法
python
from scripts.n8n_api import N8nClient
client = N8nClient()
列出工作流
workflows = client.list_workflows(active=True)
获取工作流
workflow = client.get_workflow(workflow-id)
创建工作流
newworkflow = client.createworkflow({
name: My Workflow,
nodes: [...],
connections: {...}
})
激活/停用
client.activate_workflow(workflow-id)
client.deactivate_workflow(workflow-id)
执行记录
executions = client.listexecutions(workflowid=workflow-id, limit=10)
execution = client.get_execution(execution-id)
执行工作流
result = client.execute_workflow(workflow-id, data={key: value})
验证与测试
python
from scripts.n8n_api import N8nClient
from scripts.n8n_tester import WorkflowTester
client = N8nClient()
tester = WorkflowTester(client)
验证工作流
validation = tester.validateworkflow(workflowid=123)
print(f有效: {validation[valid]})
print(f错误: {validation[errors]})
print(f警告: {validation[warnings]})
试运行
result = tester.dry_run(
workflow_id=123,
test_data={email: test@example.com}
)
print(f状态: {result[status]})
测试套件
test_cases = [
{name: 测试 1, input: {...}, expected: {...}},
{name: 测试 2, input: {...}, expected: {...}}
]
results = tester.testsuite(123, testcases)
print(f通过: {results[passed]}/{results[total_tests]})
生成报告
report = tester.generatetestreport(validation, result)
print(report)
性能优化
python
from scripts.n8n_optimizer import WorkflowOptimizer
optimizer = WorkflowOptimizer()
分析性能
analysis = optimizer.analyze_performance(workflow-id, days=7)
print(f性能评分: {analysis[performance_score]}/100)
print(f健康状态: {analysis[execution_metrics][health]})
获取建议
suggestions = optimizer.suggest_optimizations(workflow-id)
print(f优先操作: {len(suggestions[priority_actions])})
print(f快速优化: {len(suggestions[quick_wins])})
生成报告
report = optimizer.generateoptimizationreport(analysis)
print(report)
常见工作流
1. 验证和测试工作流
bash
验证工作流结构
python3 scripts/n8n_tester.py validate --id --pretty
使用样本