# n8n 表达式示例
来自 n8n 工作流的实际运行示例。
---
## 示例 1:Webhook 表单提交
**场景**:表单提交 Webhook 并发布到 Slack
**工作流**:Webhook → Slack
**Webhook 输入** (POST):
{
"name": "John Doe",
"email": "
[email protected]",
"company": "Acme Corp",
"message": "Interested in your product"
}
**Webhook 节点输出**:
{
"headers": {"content-type": "application/json"},
"params": {},
"query": {},
"body": {
"name": "John Doe",
"email": "
[email protected]",
"company": "Acme Corp",
"message": "Interested in your product"
}
}
**在 Slack 节点中** (文本字段):
New form submission! ?
Name: {{$json.body.name}}
Email: {{$json.body.email}}
Company: {{$json.body.company}}
Message: {{$json.body.message}}
**输出**:
New form submission! ?
Name: John Doe
Email:
[email protected]
Company: Acme Corp
Message: Interested in your product
---
## 示例 2:HTTP API 到数据库
**场景**:从 API 获取用户数据并插入数据库
**工作流**:定时触发 → HTTP 请求 → Postgres
**HTTP 请求返回**:
{
"data": {
"users": [
{
"id": 123,
"name": "Alice Smith",
"email": "
[email protected]",
"role": "admin"
}
]
}
}
**在 Postgres 节点中** (INSERT 语句):
sql
INSERT INTO users (user_id, name, email, role, synced_at)
VALUES (
{{$json.data.users[0].id}},
'{{$json.data.users[0].name}}',
'{{$json.data.users[0].email}}',
'{{$json.data.users[0].role}}',
'{{$now.toFormat('yyyy-MM-dd HH:mm:ss')}}'
)
**结果**:用户已插入并带有当前时间戳
---
## 示例 3:多节点数据流
**场景**:Webhook → HTTP 请求 → 电子邮件
**工作流结构**:
1. Webhook 接收订单 ID
2. HTTP 请求获取订单详情
3. 电子邮件发送确认信息
### 节点 1:Webhook
**接收**:
{
"body": {
"order_id": "ORD-12345"
}
}
### 节点 2:HTTP 请求
**URL 字段**:
https://api.example.com/orders/{{$json.body.order_id}}
**返回**:
{
"order": {
"id": "ORD-12345",
"customer": "Bob Jones",
"total": 99.99,
"items": ["Widget", "Gadget"]
}
}
### 节点 3:电子邮件
**主题**:
Order {{$node["Webhook"].json.body.order_id}} Confirmed
**正文**:
Dear {{$node["HTTP Request"].json.order.customer}},
Your order {{$node["Webhook"].json.body.order_id}} has been confirmed!
Total: ${{$node["HTTP Request"].jso