n8n Workflow Builder
Setup
Requires two environment variables:
- -
N8N_URL — n8n instance URL (e.g. https://your-n8n.example.com) - INLINECODE2 — n8n API key (Settings → API → Create API Key)
Workflow
- 1. Understand the automation — Clarify trigger (webhook/schedule/manual), data sources, processing logic, outputs, and error handling needs.
- 2. Design the workflow JSON — Build valid n8n workflow JSON following the schema in
references/workflow-schema.md. Use patterns from references/workflow-patterns.md as templates.
- 3. Deploy via API — Use
scripts/n8n-api.sh create <file> or pipe JSON to scripts/n8n-api.sh create-stdin.
- 4. Activate — Use
scripts/n8n-api.sh activate <workflow_id> for trigger-based workflows.
- 5. Verify — List workflows to confirm deployment:
scripts/n8n-api.sh list.
API Script Reference
CODEBLOCK0
Building Workflow JSON
Every workflow needs: name, nodes[], connections{}, settings{}.
Every node needs: id, name, type, typeVersion, position, parameters.
Connections use source node display name as key, mapping outputs to target nodes.
For full schema, node types, and expression syntax → read references/workflow-schema.md
For complete workflow examples (webhook, schedule, AI agent, DB sync, error handling) → read INLINECODE20
Key Rules
- - Always set
"executionOrder": "v1" in settings - Node names must be unique within a workflow
- Node IDs must be unique — use descriptive slugs like
webhook1, INLINECODE23 - Position nodes starting at
[250, 300], spacing ~200px horizontally - IF nodes have two outputs: index 0 = true, index 1 = false
- Webhook workflows need
respondToWebhook node if responseMode is INLINECODE27 - Credentials must exist in n8n before activation — check with INLINECODE28
- Test before activating — use
scripts/n8n-api.sh execute <id> for manual trigger workflows - Use
continueOnFail: true on risky HTTP/API nodes, then check for errors downstream
Common Real Estate Workflows
- - Lead intake: Webhook → validate → dedupe → insert DB → notify Slack/SMS
- Call follow-up: Schedule → query DB for completed calls → send SMS/email based on outcome
- Drip campaign: Schedule → query leads by stage → send stage-appropriate email/SMS
- CRM sync: Webhook → transform → update HubSpot/Salesforce + internal DB
- Property alerts: Schedule → scrape/API listings → filter new → notify leads
- AI qualification: Webhook → AI Agent (classify lead intent) → route to appropriate pipeline
n8n 工作流构建器
设置
需要两个环境变量:
- - N8NURL — n8n 实例 URL(例如 https://your-n8n.example.com)
- N8NAPI_KEY — n8n API 密钥(设置 → API → 创建 API 密钥)
工作流
- 1. 理解自动化需求 — 明确触发器(Webhook/定时/手动)、数据源、处理逻辑、输出以及错误处理需求。
- 2. 设计工作流 JSON — 按照 references/workflow-schema.md 中的模式构建有效的 n8n 工作流 JSON。使用 references/workflow-patterns.md 中的模式作为模板。
- 3. 通过 API 部署 — 使用 scripts/n8n-api.sh create 或通过管道将 JSON 传递给 scripts/n8n-api.sh create-stdin。
- 4. 激活 — 对于基于触发器的工作流,使用 scripts/n8n-api.sh activate 。
- 5. 验证 — 列出工作流以确认部署:scripts/n8n-api.sh list。
API 脚本参考
bash
列出所有工作流
scripts/n8n-api.sh list
从 JSON 文件创建工作流
scripts/n8n-api.sh create /tmp/workflow.json
从标准输入创建
echo {name:Test,...} | scripts/n8n-api.sh create-stdin
获取、激活、停用、删除、执行
scripts/n8n-api.sh get
scripts/n8n-api.sh activate
scripts/n8n-api.sh deactivate
scripts/n8n-api.sh delete
scripts/n8n-api.sh execute
列出凭据和标签
scripts/n8n-api.sh credentials
scripts/n8n-api.sh tags
构建工作流 JSON
每个工作流需要:name、nodes[]、connections{}、settings{}。
每个节点需要:id、name、type、typeVersion、position、parameters。
连接使用源节点显示名称作为键,将输出映射到目标节点。
有关完整模式、节点类型和表达式语法 → 阅读 references/workflow-schema.md
有关完整工作流示例(Webhook、定时、AI 代理、数据库同步、错误处理)→ 阅读 references/workflow-patterns.md
关键规则
- - 始终在设置中设置 executionOrder: v1
- 节点名称在工作流内必须唯一
- 节点 ID 必须唯一 — 使用描述性短横线命名,如 webhook1、code1
- 节点位置 从 [250, 300] 开始,水平间距约 200px
- IF 节点 有两个输出:索引 0 = 真,索引 1 = 假
- Webhook 工作流 如果 responseMode 为 responseNode,则需要 respondToWebhook 节点
- 凭据 必须在激活前存在于 n8n 中 — 使用 scripts/n8n-api.sh credentials 检查
- 激活前测试 — 对于手动触发的工作流,使用 scripts/n8n-api.sh execute
- 在风险较高的 HTTP/API 节点上使用 continueOnFail: true,然后在下游检查错误
常见房地产工作流
- - 潜在客户接收:Webhook → 验证 → 去重 → 插入数据库 → 通知 Slack/SMS
- 通话跟进:定时 → 查询数据库中已完成的通话 → 根据结果发送短信/邮件
- 培育活动:定时 → 按阶段查询潜在客户 → 发送阶段对应的邮件/SMS
- CRM 同步:Webhook → 转换 → 更新 HubSpot/Salesforce + 内部数据库
- 房产提醒:定时 → 抓取/API 房源列表 → 筛选新房源 → 通知潜在客户
- AI 资格评估:Webhook → AI 代理(分类潜在客户意图)→ 路由到相应管道