n8n-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

n8n CLI

n8n CLI

The
n8n-cli
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-cli
命令行工具可通过REST API管理n8n实例。 它会自动检测管道输出并切换为JSON格式,非常适合嵌入脚本和作为LLM工具使用。

Setup

配置方法

bash
undefined
bash
undefined

Interactive 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_...
undefined
export N8N_URL=https://my-instance.n8n.cloud export N8N_API_KEY=n8n_api_...
undefined

Global Flags

全局参数

Every command supports these flags:
FlagShortDescription
--url
-u
Instance URL (overrides config/env)
--apiKey
-k
API key (overrides config/env)
--format
-f
Output format:
table
,
json
,
id-only
--json
Shorthand for
--format=json
--jq
jq-style filter (implies
--json
), e.g.
'.[0].id'
,
'.[].name'
--quiet
-q
Suppress output
--no-header
Hide table headers (for
awk
/
cut
parsing)
--debug
Print HTTP details to stderr
Auto-JSON: When stdout is piped (not a TTY), output defaults to JSON automatically.
所有命令都支持以下参数:
FlagShortDescription
--url
-u
实例URL(会覆盖配置/环境变量中的设置)
--apiKey
-k
API密钥(会覆盖配置/环境变量中的设置)
--format
-f
输出格式:
table
json
id-only
--json
--format=json
的简写参数
--jq
jq风格的过滤器(会自动启用
--json
),例如
'.[0].id'
'.[].name'
--quiet
-q
静默模式,不输出任何内容
--no-header
隐藏表格表头(方便
awk
/
cut
解析)
--debug
将HTTP请求详情打印到标准错误流
自动JSON输出: 当标准输出被管道传输(非TTY终端环境)时,输出格式会自动默认切换为JSON。

Workflows

工作流管理

bash
undefined
bash
undefined

List 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>
undefined
n8n-cli workflow tags <id>
undefined

Executions

执行记录管理

bash
undefined
bash
undefined

List 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>
undefined
n8n-cli execution delete <id>
undefined

Credentials

凭证管理

bash
undefined
bash
undefined

List 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>
undefined
n8n-cli project members <id> n8n-cli project add-member <id> --user=<userId> --role=<role> n8n-cli project remove-member <id> --user=<userId>
undefined

Tags

标签管理

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
undefined
bash
undefined

CRUD

增删改查操作

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
undefined
cat rows.json | n8n-cli data-table add-rows <id> --stdin
undefined

Users

用户管理

bash
n8n-cli user list
n8n-cli user get <id>
bash
n8n-cli user list
n8n-cli user get <id>

Other

其他功能

bash
undefined
bash
undefined

Security 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
undefined
n8n-cli config show
undefined

Composability Patterns

组合使用模式

The CLI is designed to be piped and composed:
bash
undefined
该CLI支持管道传输和组合使用:
bash
undefined

Get 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
undefined
n8n-cli workflow list --debug 2>debug.log
undefined

Workflow 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:
  • nodes[].type
    follows the pattern
    n8n-nodes-base.<nodeName>
    for built-in nodes
  • connections
    is keyed by source node name, with
    main
    output arrays
  • Each connection specifies target
    node
    ,
    type
    (usually
    main
    ), and output
    index
  • Use
    workflow get <id> --json
    to see real examples from the instance
创建或更新工作流时,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
    (通常为
    main
    )和输出
    index
  • 可以使用
    workflow get <id> --json
    从实例中获取真实的结构示例