n8n-workflow-creator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

N8N Workflow Creator

N8N Workflow Creator

You can build and control n8n workflows using the n8n REST API. All API calls are made via the
http-request-skill
using Node.js fetch.
你可以使用n8n REST API构建和控制n8n工作流。所有API调用均通过
http-request-skill
使用Node.js fetch发起。

Configuration

配置

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
type
values when building workflow nodes:
NodeType string
Manual Trigger
n8n-nodes-base.manualTrigger
Schedule Trigger
n8n-nodes-base.scheduleTrigger
Webhook
n8n-nodes-base.webhook
HTTP Request
n8n-nodes-base.httpRequest
Set (transform)
n8n-nodes-base.set
IF (condition)
n8n-nodes-base.if
Code (JS/Python)
n8n-nodes-base.code
Send Email
n8n-nodes-base.emailSend
Slack
n8n-nodes-base.slack
Postgres
n8n-nodes-base.postgres
Notion
n8n-nodes-base.notion

构建工作流节点时使用以下
type
值:
节点类型字符串
手动触发器
n8n-nodes-base.manualTrigger
调度触发器
n8n-nodes-base.scheduleTrigger
Webhook
n8n-nodes-base.webhook
HTTP请求
n8n-nodes-base.httpRequest
设置(转换)
n8n-nodes-base.set
条件判断(IF)
n8n-nodes-base.if
代码(JS/Python)
n8n-nodes-base.code
发送邮件
n8n-nodes-base.emailSend
Slack
n8n-nodes-base.slack
Postgres
n8n-nodes-base.postgres
Notion
n8n-nodes-base.notion

Workflow Design Patterns

工作流设计模式

Pattern 1: Scheduled Report

模式1:定时报告

Schedule Trigger → HTTP Request (fetch data) → Code (transform) → Send Email
Schedule Trigger → HTTP Request (获取数据) → Code (转换) → Send Email

Pattern 2: Webhook Handler

模式2:Webhook处理器

Webhook → IF (validate) → Set (transform) → HTTP Request (action) → Respond to Webhook
Webhook → IF (验证) → Set (转换) → HTTP Request (执行操作) → 响应Webhook

Pattern 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) / Stop

Schedule → 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:
  1. Open n8n: https://n8n.srv1123427.hstgr.cloud
  2. Go to Settings → API → Create API Key
  3. Give it to Dennis to store in Mission Control credentials
Or ask Dennis to provide it directly.
如果你还没有API密钥:
  1. 打开n8n:https://n8n.srv1123427.hstgr.cloud
  2. 进入设置 → API → 创建API密钥
  3. 将其提供给Dennis,存储在Mission Control凭据中
或者直接向Dennis索要。