API、CLI 与扩展
n8n CLI
n8n CLI is a lightweight command-line client that communicates with a running n8n instance through the n8n API. It can run from any machine with network access and authenticates using an API key.
Use the API CLI to:
- List and inspect workflows
- Create a workflow from JSON
- Check recent executions
- Create a credential
- Manage projects
All operations respect the permissions of the user and the scope of the API key.
n8n CLI versus server CLI
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.
| Aspect | n8n CLI | Server CLI |
|---|---|---|
| Runs from | Any machine with network access | Same machine as n8n |
| Authentication | API key | Direct database access |
| Requires n8n running | Yes | No (not required for most operations) |
| Best for | Developers, integrations, AI agents | Instance operators, backups, emergencies |
| Permissions | Respects user roles and API key scopes | Bypasses access control |
Install n8n-cli
# Use directly with npx (zero install)
npx @n8n/cli workflow list
# Or install globally
npm install -g @n8n/cliConnect to your instance
n8n-cli config set-url https://your-instance.n8n.cloud
n8n-cli config set-api-key YOUR_API_KEY
n8n-cli config show- The configuration is saved to
~/.n8n-cli/config.jsonwith restricted file permissions (0600). - Get your API key from n8n > Settings > n8n API
Alternatively, skip the configuration file and use environment variables:
export N8N_URL=https://your-instance.n8n.cloud
export N8N_API_KEY=your_api_keyInline flags
n8n-cli --url=https://my-n8n.app.n8n.cloud --api-key=n8n_api_xxxxx workflow listResolution order
- Command-line flags (
--url,--api-key) - Environment variables (
N8N_URL,N8N_API_KEY) - Config file (
~/.n8n-cli/config.json)
Commands
Every command supports --help for detailed usage.
| Topic | Commands |
|---|---|
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 |
package (beta) |
export, import |
skill |
install |
audit |
(top-level) |
login / logout |
(top-level) |
Output formats
All commands support three output formats via --format:
| Format | Flag | Use when |
|---|---|---|
| Table | --format=table (default) |
You want human-readable terminal output |
| JSON | --format=json |
Piping to jq, programmatic use |
| ID-only | --format=id-only |
Piping to xargs, scripting |
Examples
- Human-readable table
n8n-cli workflow list- JSON for scripts
n8n-cli workflow list --format=json | jq '.[] | select(.active) | .id'- Pipe IDs into another command
n8n-cli workflow list --format=id-only | xargs -I{} n8n-cli workflow deactivate {}Use as skill with Claude Code
Install the skill so Claude always knows how to use n8n-cli:
n8n-cli skill install --globalThen 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
n8n-cli workflow list
n8n-cli workflow get <id>Create a workflow from JSON
cat workflow.json | n8n-cli workflow create --stdinCheck recent executions
n8n-cli execution list --status=error --limit=10Create a credential
n8n-cli credential schema gmailOAuth2 # see required fields first
n8n-cli credential create --type=gmailOAuth2 --name='My Gmail' --file=cred.jsonManage projects
n8n-cli project create --name="My Project"
n8n-cli workflow transfer <id> --project=<projectId>Export and import packages
n8n-cli package export --workflow-id=<workflow-id> --output=export.n8np
n8n-cli package import --file=export.n8np --conflict-policy=fail
n8n-cli package import --file=export.n8np --project=<project-id> --workflow-id-policy=source --conflict-policy=skipSee n8n packages for a detailed overview of the available flags and what makes up a package.
官方原文和授权
本页来自 N8N 英文官方网站固定快照,并转换成 xueai 静态页面。内容以 N8N 持续更新的官方页面为准。