n8n-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesen8n CLI
n8n CLI
The command-line tool manages an n8n instance via its REST API.
It auto-detects piped output and switches to JSON, making it composable for scripts and LLM tool use.
n8n-clin8n-cliSetup
配置方法
bash
undefinedbash
undefinedInteractive login (saves to ~/.n8n-cli/config.json)
交互式登录(配置会保存到 ~/.n8n-cli/config.json)
n8n-cli login
n8n-cli login
Or configure directly
或者直接手动配置
n8n-cli config set-url https://my-instance.n8n.cloud
n8n-cli config set-api-key n8n_api_...
n8n-cli config set-url https://my-instance.n8n.cloud
n8n-cli config set-api-key n8n_api_...
Or use environment variables (no config file needed)
也可以使用环境变量(无需配置文件)
export N8N_URL=https://my-instance.n8n.cloud
export N8N_API_KEY=n8n_api_...
undefinedexport N8N_URL=https://my-instance.n8n.cloud
export N8N_API_KEY=n8n_api_...
undefinedGlobal Flags
全局参数
Every command supports these flags:
| Flag | Short | Description |
|---|---|---|
| | Instance URL (overrides config/env) |
| | API key (overrides config/env) |
| | Output format: |
| Shorthand for | |
| jq-style filter (implies | |
| | Suppress output |
| Hide table headers (for | |
| Print HTTP details to stderr |
Auto-JSON: When stdout is piped (not a TTY), output defaults to JSON automatically.
所有命令都支持以下参数:
| Flag | Short | Description |
|---|---|---|
| | 实例URL(会覆盖配置/环境变量中的设置) |
| | API密钥(会覆盖配置/环境变量中的设置) |
| | 输出格式: |
| | |
| jq风格的过滤器(会自动启用 | |
| | 静默模式,不输出任何内容 |
| 隐藏表格表头(方便 | |
| 将HTTP请求详情打印到标准错误流 |
自动JSON输出: 当标准输出被管道传输(非TTY终端环境)时,输出格式会自动默认切换为JSON。
Workflows
工作流管理
bash
undefinedbash
undefinedList all workflows
列出所有工作流
n8n-cli workflow list
n8n-cli workflow list
Filter workflows
筛选工作流
n8n-cli workflow list --active
n8n-cli workflow list --tag=production
n8n-cli workflow list --name="My Workflow"
n8n-cli workflow list --limit=5
n8n-cli workflow list --active
n8n-cli workflow list --tag=production
n8n-cli workflow list --name="My Workflow"
n8n-cli workflow list --limit=5
Get a single workflow (full JSON with nodes and connections)
获取单个工作流详情(包含节点和连接关系的完整JSON)
n8n-cli workflow get <id>
n8n-cli workflow get <id>
Extract just node names from a workflow
仅提取工作流中的节点名称
n8n-cli workflow get <id> --jq '.nodes[].name'
n8n-cli workflow get <id> --jq '.nodes[].name'
Create a workflow from JSON
从JSON文件创建工作流
n8n-cli workflow create --file=workflow.json
cat workflow.json | n8n-cli workflow create --stdin
n8n-cli workflow create --file=workflow.json
cat workflow.json | n8n-cli workflow create --stdin
Update a workflow
更新工作流
n8n-cli workflow update <id> --file=updated.json
cat updated.json | n8n-cli workflow update <id> --stdin
n8n-cli workflow update <id> --file=updated.json
cat updated.json | n8n-cli workflow update <id> --stdin
Activate / deactivate
激活/停用工作流
n8n-cli workflow activate <id>
n8n-cli workflow deactivate <id>
n8n-cli workflow activate <id>
n8n-cli workflow deactivate <id>
Delete a workflow
删除工作流
n8n-cli workflow delete <id>
n8n-cli workflow delete <id>
Transfer to another project
转移到其他项目
n8n-cli workflow transfer <id> --project=<projectId>
n8n-cli workflow transfer <id> --project=<projectId>
List tags on a workflow
列出工作流的标签
n8n-cli workflow tags <id>
undefinedn8n-cli workflow tags <id>
undefinedExecutions
执行记录管理
bash
undefinedbash
undefinedList recent executions
列出最近的执行记录
n8n-cli execution list
n8n-cli execution list --workflow=<id> --status=error --limit=10
n8n-cli execution list
n8n-cli execution list --workflow=<id> --status=error --limit=10
status options: canceled, error, running, success, waiting
状态可选值:canceled(已取消)、error(执行失败)、running(运行中)、success(执行成功)、waiting(等待中)
Get execution details
获取执行详情
n8n-cli execution get <id>
n8n-cli execution get <id> --include-data # includes full node I/O
n8n-cli execution get <id>
n8n-cli execution get <id> --include-data # 包含完整的节点输入输出数据
Retry a failed execution
重试失败的执行
n8n-cli execution retry <id>
n8n-cli execution retry <id>
Stop a running execution
停止运行中的执行
n8n-cli execution stop <id>
n8n-cli execution stop <id>
Delete an execution
删除执行记录
n8n-cli execution delete <id>
undefinedn8n-cli execution delete <id>
undefinedCredentials
凭证管理
bash
undefinedbash
undefinedList credentials
列出所有凭证
n8n-cli credential list
n8n-cli credential list
Get credential metadata (not secrets)
获取凭证元数据(不含敏感密钥内容)
n8n-cli credential get <id>
n8n-cli credential get <id>
Get the schema for a credential type (shows required fields)
获取指定凭证类型的schema(展示必填字段)
n8n-cli credential schema notionApi
n8n-cli credential schema slackOAuth2Api
n8n-cli credential schema notionApi
n8n-cli credential schema slackOAuth2Api
Create a credential
创建凭证
n8n-cli credential create --type=notionApi --name='My Notion' --data='{"apiKey":"..."}'
n8n-cli credential create --type=notionApi --name='My Notion' --file=cred.json
cat cred.json | n8n-cli credential create --type=notionApi --name='My Notion' --stdin
n8n-cli credential create --type=notionApi --name='My Notion' --data='{"apiKey":"..."}'
n8n-cli credential create --type=notionApi --name='My Notion' --file=cred.json
cat cred.json | n8n-cli credential create --type=notionApi --name='My Notion' --stdin
Delete / transfer
删除/转移凭证
n8n-cli credential delete <id>
n8n-cli credential transfer <id> --project=<projectId>
**Tip:** Use `credential schema <type>` to discover required fields before creating.n8n-cli credential delete <id>
n8n-cli credential transfer <id> --project=<projectId>
**提示:** 创建凭证前可以使用`credential schema <类型>`查询所需的必填字段。Projects
项目管理
bash
n8n-cli project list
n8n-cli project get <id>
n8n-cli project create --name="My Project"
n8n-cli project update <id> --name="New Name"
n8n-cli project delete <id>bash
n8n-cli project list
n8n-cli project get <id>
n8n-cli project create --name="My Project"
n8n-cli project update <id> --name="New Name"
n8n-cli project delete <id>Team management
团队管理
n8n-cli project members <id>
n8n-cli project add-member <id> --user=<userId> --role=<role>
n8n-cli project remove-member <id> --user=<userId>
undefinedn8n-cli project members <id>
n8n-cli project add-member <id> --user=<userId> --role=<role>
n8n-cli project remove-member <id> --user=<userId>
undefinedTags
标签管理
bash
n8n-cli tag list
n8n-cli tag create --name=production
n8n-cli tag update <id> --name=staging
n8n-cli tag delete <id>bash
n8n-cli tag list
n8n-cli tag create --name=production
n8n-cli tag update <id> --name=staging
n8n-cli tag delete <id>Variables
变量管理
bash
n8n-cli variable list
n8n-cli variable create --key=API_ENDPOINT --value=https://api.example.com
n8n-cli variable update <id> --key=API_ENDPOINT --value=https://new-api.example.com
n8n-cli variable delete <id>bash
n8n-cli variable list
n8n-cli variable create --key=API_ENDPOINT --value=https://api.example.com
n8n-cli variable update <id> --key=API_ENDPOINT --value=https://new-api.example.com
n8n-cli variable delete <id>Data Tables
数据表管理
bash
undefinedbash
undefinedCRUD
增删改查操作
n8n-cli data-table list
n8n-cli data-table get <id>
n8n-cli data-table create --name=Inventory --columns='[{"name":"item","type":"string"},{"name":"qty","type":"number"}]'
n8n-cli data-table delete <id>
n8n-cli data-table list
n8n-cli data-table get <id>
n8n-cli data-table create --name=Inventory --columns='[{"name":"item","type":"string"},{"name":"qty","type":"number"}]'
n8n-cli data-table delete <id>
Row operations
行操作
n8n-cli data-table rows <id>
n8n-cli data-table add-rows <id> --file=rows.json
n8n-cli data-table update-rows <id> --file=rows.json
n8n-cli data-table upsert-rows <id> --file=rows.json
n8n-cli data-table delete-rows <id> --ids=row1,row2,row3
n8n-cli data-table rows <id>
n8n-cli data-table add-rows <id> --file=rows.json
n8n-cli data-table update-rows <id> --file=rows.json
n8n-cli data-table upsert-rows <id> --file=rows.json
n8n-cli data-table delete-rows <id> --ids=row1,row2,row3
All row commands support --stdin
所有行操作都支持--stdin参数
cat rows.json | n8n-cli data-table add-rows <id> --stdin
undefinedcat rows.json | n8n-cli data-table add-rows <id> --stdin
undefinedUsers
用户管理
bash
n8n-cli user list
n8n-cli user get <id>bash
n8n-cli user list
n8n-cli user get <id>Other
其他功能
bash
undefinedbash
undefinedSecurity audit
安全审计
n8n-cli audit
n8n-cli audit --categories=credentials,nodes
n8n-cli audit
n8n-cli audit --categories=credentials,nodes
Source control
源代码控制
n8n-cli source-control pull
n8n-cli source-control pull
View config
查看配置
n8n-cli config show
undefinedn8n-cli config show
undefinedComposability Patterns
组合使用模式
The CLI is designed to be piped and composed:
bash
undefined该CLI支持管道传输和组合使用:
bash
undefinedGet all workflow IDs
获取所有工作流ID
n8n-cli workflow list --jq '.[].id'
n8n-cli workflow list --jq '.[].id'
Get the name of the first workflow
获取第一个工作流的名称
n8n-cli workflow list --jq '.[0].name'
n8n-cli workflow list --jq '.[0].name'
Export a workflow to a file
导出工作流到文件
n8n-cli workflow get 1234 --json > workflow-backup.json
n8n-cli workflow get 1234 --json > workflow-backup.json
Find failing executions for a workflow
查找指定工作流的失败执行记录
n8n-cli execution list --workflow=1234 --status=error --json
n8n-cli execution list --workflow=1234 --status=error --json
Pipe workflow JSON for modification
管道传输工作流JSON进行修改
n8n-cli workflow get 1234 --json | jq '.name = "Updated Name"' | n8n-cli workflow update 1234 --stdin
n8n-cli workflow get 1234 --json | jq '.name = "Updated Name"' | n8n-cli workflow update 1234 --stdin
Table output without headers for shell parsing
输出不带表头的表格,方便shell解析
n8n-cli workflow list --no-header | awk '{print $1}'
n8n-cli workflow list --no-header | awk '{print $1}'
Debug API calls
调试API请求
n8n-cli workflow list --debug 2>debug.log
undefinedn8n-cli workflow list --debug 2>debug.log
undefinedWorkflow JSON Structure
工作流JSON结构
When creating or updating workflows, the JSON follows this structure:
json
{
"name": "My Workflow",
"nodes": [
{
"name": "Start",
"type": "n8n-nodes-base.manualTrigger",
"position": [250, 300],
"parameters": {}
},
{
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"position": [450, 300],
"parameters": {
"url": "https://api.example.com/data",
"method": "GET"
}
}
],
"connections": {
"Start": {
"main": [[{ "node": "HTTP Request", "type": "main", "index": 0 }]]
}
}
}Key points:
- follows the pattern
nodes[].typefor built-in nodesn8n-nodes-base.<nodeName> - is keyed by source node name, with
connectionsoutput arraysmain - Each connection specifies target ,
node(usuallytype), and outputmainindex - Use to see real examples from the instance
workflow get <id> --json
创建或更新工作流时,JSON需要遵循以下结构:
json
{
"name": "My Workflow",
"nodes": [
{
"name": "Start",
"type": "n8n-nodes-base.manualTrigger",
"position": [250, 300],
"parameters": {}
},
{
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"position": [450, 300],
"parameters": {
"url": "https://api.example.com/data",
"method": "GET"
}
}
],
"connections": {
"Start": {
"main": [[{ "node": "HTTP Request", "type": "main", "index": 0 }]]
}
}
}核心要点:
- 内置节点的遵循
nodes[].type的命名规则n8n-nodes-base.<节点名称> - 以源节点名称为键,包含
connections输出数组main - 每个连接指定目标、
node(通常为type)和输出mainindex - 可以使用从实例中获取真实的结构示例
workflow get <id> --json