n8n-workflow-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseN8N Workflow Creator
N8N Workflow Creator
You can build and control n8n workflows using the n8n REST API. All API calls are made via the using Node.js fetch.
http-request-skill你可以使用n8n REST API构建和控制n8n工作流。所有API调用均通过使用Node.js fetch发起。
http-request-skillConfiguration
配置
N8N_BASE_URL = https://n8n.srv1123427.hstgr.cloud
N8N_API_KEY = (set via Mission Control credentials or ask Dennis)Always include the API key header:
X-N8N-API-KEY: <your-api-key>N8N_BASE_URL = https://n8n.srv1123427.hstgr.cloud
N8N_API_KEY = (通过Mission Control凭据设置或咨询Dennis)务必包含API密钥请求头:
X-N8N-API-KEY: <your-api-key>Core API Commands
核心API命令
1. List all workflows
1. 列出所有工作流
bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows', {
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' }
}).then(r => r.json()).then(d => console.log(JSON.stringify(d.data?.map(w => ({id: w.id, name: w.name, active: w.active})), null, 2)));
"bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows', {
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' }
}).then(r => r.json()).then(d => console.log(JSON.stringify(d.data?.map(w => ({id: w.id, name: w.name, active: w.active})), null, 2)));
"2. Get a specific workflow
2. 获取特定工作流
bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID', {
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY' }
}).then(r => r.json()).then(d => console.log(JSON.stringify({id: d.id, name: d.name, active: d.active, nodes: d.nodes?.length}, null, 2)));
"bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID', {
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY' }
}).then(r => r.json()).then(d => console.log(JSON.stringify({id: d.id, name: d.name, active: d.active, nodes: d.nodes?.length}, null, 2)));
"3. Activate a workflow
3. 激活工作流
bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID/activate', {
method: 'POST',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' }
}).then(r => r.json()).then(console.log);
"bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID/activate', {
method: 'POST',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' }
}).then(r => r.json()).then(console.log);
"4. Deactivate a workflow
4. 停用工作流
bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID/deactivate', {
method: 'POST',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' }
}).then(r => r.json()).then(console.log);
"bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID/deactivate', {
method: 'POST',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' }
}).then(r => r.json()).then(console.log);
"5. Create a new workflow
5. 创建新工作流
bash
node -e "
const workflow = {
name: 'My New Workflow',
nodes: [
{
id: 'start',
name: 'Start',
type: 'n8n-nodes-base.manualTrigger',
typeVersion: 1,
position: [250, 300],
parameters: {}
},
{
id: 'set1',
name: 'Set Data',
type: 'n8n-nodes-base.set',
typeVersion: 3,
position: [450, 300],
parameters: {
mode: 'manual',
assignments: {
assignments: [{ id: '1', name: 'result', value: 'Hello from OpenClaw!', type: 'string' }]
}
}
}
],
connections: {
'Start': { main: [[{ node: 'Set Data', type: 'main', index: 0 }]] }
},
settings: { executionOrder: 'v1' }
};
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows', {
method: 'POST',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' },
body: JSON.stringify(workflow)
}).then(r => r.json()).then(d => console.log('Created workflow ID:', d.id));
"bash
node -e "
const workflow = {
name: 'My New Workflow',
nodes: [
{
id: 'start',
name: 'Start',
type: 'n8n-nodes-base.manualTrigger',
typeVersion: 1,
position: [250, 300],
parameters: {}
},
{
id: 'set1',
name: 'Set Data',
type: 'n8n-nodes-base.set',
typeVersion: 3,
position: [450, 300],
parameters: {
mode: 'manual',
assignments: {
assignments: [{ id: '1', name: 'result', value: 'Hello from OpenClaw!', type: 'string' }]
}
}
}
],
connections: {
'Start': { main: [[{ node: 'Set Data', type: 'main', index: 0 }]] }
},
settings: { executionOrder: 'v1' }
};
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows', {
method: 'POST',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' },
body: JSON.stringify(workflow)
}).then(r => r.json()).then(d => console.log('Created workflow ID:', d.id));
"6. Execute a workflow (manual trigger)
6. 执行工作流(手动触发)
bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID/execute', {
method: 'POST',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' },
body: JSON.stringify({ startNodes: [] })
}).then(r => r.json()).then(d => console.log('Execution ID:', d.executionId || d.id));
"bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID/execute', {
method: 'POST',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY', 'Content-Type': 'application/json' },
body: JSON.stringify({ startNodes: [] })
}).then(r => r.json()).then(d => console.log('Execution ID:', d.executionId || d.id));
"7. Check execution status/logs
7. 检查执行状态/日志
bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/executions?workflowId=WORKFLOW_ID&limit=5', {
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY' }
}).then(r => r.json()).then(d => {
const execs = d.data || [];
console.log(JSON.stringify(execs.map(e => ({id: e.id, status: e.status, startedAt: e.startedAt})), null, 2));
});
"bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/executions?workflowId=WORKFLOW_ID&limit=5', {
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY' }
}).then(r => r.json()).then(d => {
const execs = d.data || [];
console.log(JSON.stringify(execs.map(e => ({id: e.id, status: e.status, startedAt: e.startedAt})), null, 2));
});
"8. Delete a workflow
8. 删除工作流
bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID', {
method: 'DELETE',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY' }
}).then(r => console.log('Deleted:', r.status));
"bash
node -e "
fetch('https://n8n.srv1123427.hstgr.cloud/api/v1/workflows/WORKFLOW_ID', {
method: 'DELETE',
headers: { 'X-N8N-API-KEY': 'YOUR_API_KEY' }
}).then(r => console.log('Deleted:', r.status));
"Common Node Types
常见节点类型
Use these values when building workflow nodes:
type| Node | Type string |
|---|---|
| Manual Trigger | |
| Schedule Trigger | |
| Webhook | |
| HTTP Request | |
| Set (transform) | |
| IF (condition) | |
| Code (JS/Python) | |
| Send Email | |
| Slack | |
| Postgres | |
| Notion | |
构建工作流节点时使用以下值:
type| 节点 | 类型字符串 |
|---|---|
| 手动触发器 | |
| 调度触发器 | |
| Webhook | |
| HTTP请求 | |
| 设置(转换) | |
| 条件判断(IF) | |
| 代码(JS/Python) | |
| 发送邮件 | |
| Slack | |
| Postgres | |
| Notion | |
Workflow Design Patterns
工作流设计模式
Pattern 1: Scheduled Report
模式1:定时报告
Schedule Trigger → HTTP Request (fetch data) → Code (transform) → Send EmailSchedule Trigger → HTTP Request (获取数据) → Code (转换) → Send EmailPattern 2: Webhook Handler
模式2:Webhook处理器
Webhook → IF (validate) → Set (transform) → HTTP Request (action) → Respond to WebhookWebhook → IF (验证) → Set (转换) → HTTP Request (执行操作) → 响应WebhookPattern 3: Database Sync
模式3:数据库同步
Schedule → Postgres (read) → Split In Batches → HTTP Request (send) → Postgres (update)Schedule → Postgres (读取) → Split In Batches → HTTP Request (发送) → Postgres (更新)Pattern 4: Alert System
模式4:告警系统
Schedule → HTTP Request (check service) → IF (error?) → Slack (alert) / StopSchedule → HTTP Request (检查服务) → IF (是否出错?) → Slack (告警) / 停止Workflow JSON Structure
工作流JSON结构
Every workflow needs these keys:
json
{
"name": "Workflow Name",
"nodes": [ ...node objects... ],
"connections": {
"Node Name": {
"main": [[{ "node": "Next Node Name", "type": "main", "index": 0 }]]
}
},
"settings": { "executionOrder": "v1" }
}Node object structure:
json
{
"id": "unique-id",
"name": "Human Name",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [x, y],
"parameters": { ...node-specific params... }
}每个工作流都需要包含以下键:
json
{
"name": "Workflow Name",
"nodes": [ ...node objects... ],
"connections": {
"Node Name": {
"main": [[{ "node": "Next Node Name", "type": "main", "index": 0 }]]
}
},
"settings": { "executionOrder": "v1" }
}节点对象结构:
json
{
"id": "unique-id",
"name": "Human Name",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [x, y],
"parameters": { ...node-specific params... }
}Best Practices
最佳实践
- Always validate JSON before sending CREATE requests (invalid JSON = 400 error)
- Use descriptive names for nodes (not "Node 1" but "Fetch Oplevertool Data")
- Handle errors by adding an Error Trigger workflow that sends Slack/email alerts
- Test with manual trigger before activating scheduled/webhook workflows
- Check execution logs after first run to confirm correct behavior
- Avoid hardcoded secrets in Code nodes — use n8n Credentials instead
- 发送创建请求前务必验证JSON(无效JSON会返回400错误)
- 为节点使用描述性名称(不要用“节点1”,而是类似“获取Oplevertool数据”)
- 处理错误:添加错误触发工作流,发送Slack/邮件告警
- 激活定时/Webhook工作流前先使用手动触发器测试
- 首次运行后检查执行日志,确认行为正确
- 避免在Code节点中硬编码密钥——改用n8n凭据
Getting Your API Key
获取API密钥
If you don't have an API key yet:
- Open n8n: https://n8n.srv1123427.hstgr.cloud
- Go to Settings → API → Create API Key
- Give it to Dennis to store in Mission Control credentials
Or ask Dennis to provide it directly.
如果你还没有API密钥:
- 打开n8n:https://n8n.srv1123427.hstgr.cloud
- 进入设置 → API → 创建API密钥
- 将其提供给Dennis,存储在Mission Control凭据中
或者直接向Dennis索要。