Command-line tool for managing n8n workflows and troubleshooting executions
Project description
n8n CLI
Python CLI for managing n8n workflows and troubleshooting executions.
Requirements
- Python 3.11+
- uv (recommended) or pip
Setup
1. Get your n8n API key
- Open your n8n instance
- Go to Settings → n8n API
- Click Create API Key
- Copy the generated key
2. Set environment variables
export N8N_API_KEY="your-api-key-here"
export N8N_BASE_URL="https://your-instance.app.n8n.cloud"
Or create a .envrc file (if using direnv):
export N8N_API_KEY="your-api-key-here"
export N8N_BASE_URL="https://your-instance.app.n8n.cloud"
3. Run the CLI
No installation needed - uses uv run with inline script dependencies:
uv run n8n-cli --help
CLI Usage
Workflows
# List all workflows
uv run n8n-cli workflows
uv run n8n-cli workflows --active
uv run n8n-cli workflows --json
# Get workflow details
uv run n8n-cli workflow <workflow_id>
uv run n8n-cli workflow <workflow_id> --json
# Update workflow from JSON file
uv run n8n-cli update <workflow_id> workflow.json
# Activate/deactivate workflows
uv run n8n-cli activate <workflow_id>
uv run n8n-cli deactivate <workflow_id>
Nodes (view and edit workflow nodes)
# List all nodes in a workflow
uv run n8n-cli nodes <workflow_id>
# View node details
uv run n8n-cli node <workflow_id> "node name"
uv run n8n-cli node <workflow_id> "node name" --json
# View Code node's JavaScript
uv run n8n-cli node <workflow_id> "node name" --code
# Update Code node from file
uv run n8n-cli node <workflow_id> "node name" --set-code script.js
# Rename a node
uv run n8n-cli node <workflow_id> "old name" --rename "new name"
# Rename and update code in one command
uv run n8n-cli node <workflow_id> "old name" --rename "new name" --set-code script.js
Export/Import Code Nodes
Useful for editing Code node scripts in a proper editor with syntax highlighting.
# Export all Code nodes to a directory
uv run n8n-cli export-code <workflow_id> ./nodes/
# Creates: ./nodes/node_name.js, ./nodes/_manifest.json
# Edit the scripts with your editor...
# Import updated scripts back to workflow
uv run n8n-cli import-code <workflow_id> ./nodes/
Trigger Workflows
# Trigger workflow by name via webhook
uv run n8n-cli trigger "Alerting"
# Trigger with JSON payload
uv run n8n-cli trigger "Alerting" --data '{"key": "value"}'
# Trigger with payload from file
uv run n8n-cli trigger "Alerting" --file payload.json
# Use test webhook URL (for debugging)
uv run n8n-cli trigger "Alerting" --test --data '{"test": true}'
# Run workflow directly (not via webhook)
uv run n8n-cli run <workflow_id>
uv run n8n-cli run <workflow_id> --data '{"input": "data"}'
uv run n8n-cli run <workflow_id> --output # show node outputs
Executions
# List executions
uv run n8n-cli executions
uv run n8n-cli executions --workflow <workflow_id>
uv run n8n-cli executions --status error
uv run n8n-cli executions -n 100
# Get execution details (includes error info for failed executions)
uv run n8n-cli execution <execution_id>
uv run n8n-cli execution <execution_id> --data # full execution data
# Retry failed execution
uv run n8n-cli retry <execution_id>
uv run n8n-cli retry <execution_id> --latest # use current workflow version
Python API Usage
# /// script
# dependencies = ["httpx"]
# ///
from n8n_client import N8nClient
client = N8nClient()
# List workflows
workflows = client.get_workflows()
for wf in workflows.data:
print(f"{wf['id']}: {wf['name']}")
# Get all pages
all_workflows = client.get_all_pages(client.get_workflows, active=True)
# Get workflow details
wf = client.get_workflow("workflow_id")
# Get executions for a workflow
executions = client.get_executions(workflow_id="workflow_id", status="error")
# Get execution with full data
ex = client.get_execution("execution_id", include_data=True)
# Retry failed execution
client.retry_execution("execution_id")
# Activate/deactivate
client.activate_workflow("workflow_id")
client.deactivate_workflow("workflow_id")
Common Workflows
Editing Code Nodes
# 1. Export all Code nodes to files
uv run n8n-cli export-code <workflow_id> ./nodes/
# 2. Edit scripts in your editor (with syntax highlighting)
code ./nodes/
# 3. Import changes back
uv run n8n-cli import-code <workflow_id> ./nodes/
Quick Node Update
# View current code
uv run n8n-cli node <workflow_id> "node name" --code > script.js
# Edit and update
uv run n8n-cli node <workflow_id> "node name" --set-code script.js
Troubleshooting Executions
# Find failed executions
uv run n8n-cli executions --status error
# Get error details
uv run n8n-cli execution <id>
# Get full execution data for debugging
uv run n8n-cli execution <id> --data --json
Testing Webhook Workflows
# Trigger with test payload
uv run n8n-cli trigger "Workflow Name" --test --file test_payload.json
# Check execution result
uv run n8n-cli executions --workflow <id> -n 1
API Endpoints Covered
- Workflows: list, get, create, update, delete, activate, deactivate, tags
- Executions: list, get, delete, retry
- Tags: list, get, create, update, delete
- Credentials: create, delete, schema
- Users: list
- Audit: generate security audit
- Variables: list, create, delete
- Projects: list
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file n8n_client-1.0.0.tar.gz.
File metadata
- Download URL: n8n_client-1.0.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d47c1214eecf901f630f5a13347807c9c343d1fda6d4e13ae99f8883a38b2e6f
|
|
| MD5 |
5d6e68de02967f674710da0db97812e6
|
|
| BLAKE2b-256 |
d169b241da711fe3801942a467c2d6efdfc072a42c52d78fa44b0ac48f1ee389
|
Provenance
The following attestation bundles were made for n8n_client-1.0.0.tar.gz:
Publisher:
publish.yml on pokgak/n8n-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
n8n_client-1.0.0.tar.gz -
Subject digest:
d47c1214eecf901f630f5a13347807c9c343d1fda6d4e13ae99f8883a38b2e6f - Sigstore transparency entry: 928387557
- Sigstore integration time:
-
Permalink:
pokgak/n8n-client@4206ba1176029323b717ecaaf77bed09e5402f02 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/pokgak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4206ba1176029323b717ecaaf77bed09e5402f02 -
Trigger Event:
release
-
Statement type:
File details
Details for the file n8n_client-1.0.0-py3-none-any.whl.
File metadata
- Download URL: n8n_client-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7df247aa3c469287fc36020264b7595ce3c1198ffbf5b40dc5e5dc974b49624e
|
|
| MD5 |
31f07f7c445057fb2dcf3aefdeaaba7a
|
|
| BLAKE2b-256 |
2be03ac5c18f4ba2e3150ac5d9c118c85043124b96f93538cee9d917170b958e
|
Provenance
The following attestation bundles were made for n8n_client-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on pokgak/n8n-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
n8n_client-1.0.0-py3-none-any.whl -
Subject digest:
7df247aa3c469287fc36020264b7595ce3c1198ffbf5b40dc5e5dc974b49624e - Sigstore transparency entry: 928387559
- Sigstore integration time:
-
Permalink:
pokgak/n8n-client@4206ba1176029323b717ecaaf77bed09e5402f02 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/pokgak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4206ba1176029323b717ecaaf77bed09e5402f02 -
Trigger Event:
release
-
Statement type: