开始使用 n8n CLI(Getting started with n8n CLI)#
n8n CLI 是一个轻量级的命令行客户端,通过 n8n API 与正在运行的 n8n 实例进行通信。它可以从任何具有网络访问的计算机上运行,并使用 API 密钥进行身份验证。
n8n CLI 正处于测试阶段
仅将其用于实验、本地开发和个人项目,而不用于生产工作流程。
使用 API CLI 来:
🌐 Use the API CLI to:
- 列出并检查工作流
- 从 JSON 创建工作流
- 查看最近的处决
- 创建凭据
- 管理项目
所有操作都遵守用户的权限和 API 密钥的范围。
🌐 All operations respect the permissions of the user and the scope of the API key.
n8n CLI 与服务器 CLI(n8n CLI versus server CLI)#
如果你需要管理你的 n8n 实例(备份、许可证管理、紧急重置),请参考 Server CLI,这是一个运行在与 n8n 相同机器上的内置工具。
🌐 If you need to manage your n8n instance (backups, license management, emergency resets), see the Server CLI, a built-in tool that runs on the same machine as n8n.
| 方面 | n8n CLI | 服务器 CLI |
|---|---|---|
| 运行地点 | 任何有网络访问的机器 | 与 n8n 相同的机器 |
| 认证方式 | API 密钥 | 直接数据库访问 |
| 需要 n8n 运行 | 是 | 否(大多数操作不需要) |
| 最佳适用对象 | 开发者、集成、AI 代理 | 实例运算符、备份、紧急情况 |
| 权限 | 遵循用户角色和 API 密钥权限范围 | 绕过访问控制 |
安装 n8n-cli(Install n8n-cli)#
1 2 3 4 5 | |
连接到你的实例(Connect to your instance)#
1 2 3 | |
- 配置已保存到
~/.n8n-cli/config.json,并具有受限的文件权限(0600)。 - 从 n8n > 设置 > n8n API 获取你的 API 密钥
或者,跳过配置文件,使用环境变量:
🌐 Alternatively, skip the configuration file and use environment variables:
1 2 | |
内联标志(Inline flags)#
1 | |
决议顺序(Resolution order)#
- 命令行标志(
--url,--api-key) - 环境变量(
N8N_URL,N8N_API_KEY) - 配置文件 (
~/.n8n-cli/config.json)
命令(Commands)#
每个命令都支持 --help 来查看详细用法。
🌐 Every command supports --help for detailed usage.
| 主题 | 命令 |
|---|---|
workflow |
list, get, create, update, delete, activate, deactivate, tags, transfer |
execution |
list, get, retry, stop, delete |
credential |
list, get, schema, create, delete, transfer |
project |
list, get, create, update, delete, members, add-member, remove-member |
tag |
list, create, update, delete |
variable |
list, create, update, delete |
data-table |
list, get, create, delete, rows, add-rows, update-rows, upsert-rows, delete-rows |
user |
list, get |
config |
set-url, set-api-key, show |
source-control |
pull |
skill |
install |
audit |
(顶层) |
login / logout |
(顶层) |
输出格式(Output formats)#
所有命令通过 --format 支持三种输出格式:
🌐 All commands support three output formats via --format:
| 格式 | 标志 | 使用场景 |
|---|---|---|
| 表格 | --format=table(默认) |
你想要人类可读的终端输出 |
| JSON | --format=json |
管道给 jq,程序化使用 |
| 仅 ID | --format=id-only |
管道给 xargs,脚本使用 |
示例(Examples)#
- 人类可读表
1 | |
- 脚本的 JSON
1 | |
- 将管道ID输入到另一个命令中
1 | |
作为技能使用 Claude 代码(Use as skill with Claude Code)#
安装该技能,以便 Claude 始终知道如何使用 n8n-cli:
🌐 Install the skill so Claude always knows how to use n8n-cli:
1 | |
然后在 Claude 代码中,输入 /n8n-cli 来加载它。Claude 现在可以代表你创建、更新和管理工作流,而无需 MCP。
🌐 Then in Claude Code, type /n8n-cli to load it. Claude can now create, update, and manage workflows on your behalf without requiring an MCP.
示例(Examples)#
列出并检查工作流(List and inspect workflows)#
1 2 | |
从 JSON 创建工作流(Create a workflow from JSON)#
1 | |
查看最近的处决(Check recent executions)#
1 | |
创建凭据(Create a credential)#
1 2 | |
管理项目(Manage projects)#
1 2 | |