n8n REST API Skill
Interact with an n8n automation platform instance via its public REST API v1.
Environment Variables (REQUIRED)
Before making any API calls, ensure these environment variables are set:
| Variable | Description | Example |
|---|
| n8n instance hostname (with protocol, no trailing slash) | |
| API key generated in n8n UI (Settings > API) | |
bash
export N8N_HOST="https://n8n.example.com"
export N8N_API_KEY="your-api-key-here"
If these are not set, ask the user to provide them before proceeding.
Authentication
All requests require the
header:
bash
curl -H "X-N8N-API-KEY: $N8N_API_KEY" "$N8N_HOST/api/v1/workflows"
Every request pattern below assumes:
- Base URL:
- Header:
X-N8N-API-KEY: $N8N_API_KEY
- Content-Type: (for POST/PUT/PATCH)
API Endpoints
Workflows
| Method | Path | Description |
|---|
| GET | | List all workflows (supports , , , ) |
| GET | | Get a single workflow by ID |
| POST | | Create a new workflow |
| PUT | | Update an existing workflow (full replace) |
| DELETE | | Delete a workflow |
| POST | | Activate a workflow |
| POST | /workflows/{id}/deactivate
| Deactivate a workflow |
| POST | | Transfer workflow to another project |
List workflows
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/workflows?limit=50" | jq .
Query parameters:
- (boolean) — filter by active/inactive status
- (string) — filter by tag ID
- (string) — filter by name (partial match)
- (number) — results per page (default 10, max 250)
- (string) — pagination cursor from previous response
Get a workflow
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/workflows/{id}" | jq .
Create a workflow
bash
curl -s -X POST \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "My Workflow",
"nodes": [],
"connections": {},
"settings": {
"executionOrder": "v1"
}
}' \
"$N8N_HOST/api/v1/workflows" | jq .
Request body fields:
- (string, required) — workflow name
- (array, required) — array of node objects
- (object, required) — node connections map
- (object) — workflow settings
- (object) — static data for the workflow
- (array of objects) — tags to assign
Update a workflow
bash
curl -s -X PUT \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Workflow",
"nodes": [...],
"connections": {...},
"settings": {...}
}' \
"$N8N_HOST/api/v1/workflows/{id}" | jq .
Note: If the workflow is active, the updated version is automatically re-published.
Activate / Deactivate
bash
# Activate
curl -s -X POST -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/workflows/{id}/activate" | jq .
# Deactivate
curl -s -X POST -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/workflows/{id}/deactivate" | jq .
Delete a workflow
bash
curl -s -X DELETE -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/workflows/{id}" | jq .
Executions
| Method | Path | Description |
|---|
| GET | | List executions (supports filters) |
| GET | | Get a single execution |
| DELETE | | Delete an execution |
| POST | | Stop a running execution |
List executions
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/executions?limit=20&status=error" | jq .
Query parameters:
- (string) — filter by workflow ID
- (string) — , , ,
- (number) — results per page (default 10, max 250)
- (string) — pagination cursor
- (boolean) — include full execution data (default false)
Get execution details
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/executions/{id}?includeData=true" | jq .
Response includes:
- — execution ID
- — boolean
- — trigger mode (manual, webhook, trigger, etc.)
- / — timestamps
- — associated workflow
- — success/error/waiting/running
- — full execution data (when )
Stop a running execution
bash
curl -s -X POST -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/executions/{id}/stop" | jq .
Credentials
| Method | Path | Description |
|---|
| GET | | List all credentials |
| POST | | Create new credential |
| DELETE | | Delete a credential |
| POST | /credentials/{id}/transfer
| Transfer credential to another project |
List credentials
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/credentials?limit=50" | jq .
Query parameters:
- (number) — results per page
- (string) — pagination cursor
Create credential
bash
curl -s -X POST \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "My API Key",
"type": "httpHeaderAuth",
"data": {
"name": "Authorization",
"value": "Bearer token123"
}
}' \
"$N8N_HOST/api/v1/credentials" | jq .
Request body:
- (string, required) — credential name
- (string, required) — credential type (e.g., , , )
- (object, required) — credential-specific data
Security note: The API does not return credential secrets in GET responses. Only metadata (id, name, type, createdAt, updatedAt) is returned.
Tags
| Method | Path | Description |
|---|
| GET | | List all tags |
| GET | | Get a single tag |
| POST | | Create a new tag |
| PUT | | Update a tag |
| DELETE | | Delete a tag |
List tags
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/tags?limit=100" | jq .
Create tag
bash
curl -s -X POST \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "production"}' \
"$N8N_HOST/api/v1/tags" | jq .
Update tag
bash
curl -s -X PUT \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "staging"}' \
"$N8N_HOST/api/v1/tags/{id}" | jq .
Variables
| Method | Path | Description |
|---|
| GET | | List all variables |
| POST | | Create a variable |
| PUT | | Update a variable |
| DELETE | | Delete a variable |
List variables
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/variables" | jq .
Create variable
bash
curl -s -X POST \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{"key": "API_ENDPOINT", "value": "https://api.example.com"}' \
"$N8N_HOST/api/v1/variables" | jq .
Update variable
bash
curl -s -X PUT \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{"key": "API_ENDPOINT", "value": "https://api-v2.example.com"}' \
"$N8N_HOST/api/v1/variables/{id}" | jq .
Users
| Method | Path | Description |
|---|
| GET | | List all users |
| GET | | Get user by ID (or ) |
List users
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/users?limit=50" | jq .
Query parameters:
- (number) — results per page
- (string) — pagination cursor
- (boolean) — include role in response
Projects
| Method | Path | Description |
|---|
| GET | | List all projects |
| GET | | Get project by ID |
| POST | | Create a project |
| PUT | | Update a project |
| DELETE | | Delete a project |
List projects
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/projects" | jq .
Create project
bash
curl -s -X POST \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Marketing Automations"}' \
"$N8N_HOST/api/v1/projects" | jq .
Audit
| Method | Path | Description |
|---|
| POST | | Generate a security audit report |
Generate audit
bash
curl -s -X POST \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{"additionalOptions": {"categories": ["credentials", "nodes", "instance"]}}' \
"$N8N_HOST/api/v1/audit" | jq .
Audit categories:
,
,
,
,
.
Source Control
| Method | Path | Description |
|---|
| GET | /source-control/preferences
| Get source control preferences |
| POST | /source-control/preferences
| Set source control preferences |
| POST | | Pull changes from remote |
| POST | | Push changes to remote |
| GET | | Get modified resources status |
| POST | /source-control/disconnect
| Disconnect from source control |
Get status
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/source-control/status" | jq .
Pull from remote
bash
curl -s -X POST \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{"force": false}' \
"$N8N_HOST/api/v1/source-control/pull" | jq .
Pagination
The n8n API uses cursor-based pagination. Responses include:
json
{
"data": [...],
"nextCursor": "eyJsaW1pdCI6MTAsIm9mZnNldCI6MTB9"
}
To fetch the next page, pass
on the next request. When
is
, there are no more results.
Common Patterns
List all workflows with their status
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/workflows?limit=250" | \
jq '.data[] | {id, name, active, updatedAt}'
Find failed executions for a workflow
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/executions?workflowId=123&status=error&limit=50" | \
jq '.data[] | {id, status, startedAt, stoppedAt}'
Trigger a workflow manually via webhook
If a workflow has a Webhook node, you can trigger it directly:
bash
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"key": "value"}' \
"$N8N_HOST/webhook/{webhook-path}"
Note: Webhook URLs use
or
path, not
.
Export a workflow as JSON
bash
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/workflows/{id}" | jq . > workflow-backup.json
Import / restore a workflow from JSON
bash
curl -s -X POST \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d @workflow-backup.json \
"$N8N_HOST/api/v1/workflows" | jq .
Bulk activate all workflows
bash
# Get all inactive workflow IDs, then activate each
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/workflows?active=false&limit=250" | \
jq -r '.data[].id' | while read id; do
curl -s -X POST -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/workflows/$id/activate" > /dev/null
echo "Activated workflow $id"
done
Delete old executions (cleanup)
bash
# Get executions older than a specific date and delete them
curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/executions?status=success&limit=100" | \
jq -r '.data[].id' | while read id; do
curl -s -X DELETE -H "X-N8N-API-KEY: $N8N_API_KEY" \
"$N8N_HOST/api/v1/executions/$id" > /dev/null
echo "Deleted execution $id"
done
Error Handling
Common HTTP status codes:
| Code | Meaning |
|---|
| 200 | Success |
| 201 | Created |
| 400 | Bad request (invalid parameters) |
| 401 | Unauthorized (missing or invalid API key) |
| 403 | Forbidden (insufficient permissions) |
| 404 | Resource not found |
| 500 | Internal server error |
Error response format:
json
{
"code": 404,
"message": "The requested workflow was not found"
}
Implementation Notes
- Always read and from environment variables — never hardcode them
- Use for JSON processing in shell scripts
- For Node.js scripts, use or with the same headers
- Rate limiting: n8n does not enforce strict rate limits by default, but be respectful on shared instances
- Pagination: always handle for endpoints that return lists
- Webhook URLs are separate from the API ( vs )
- Execution data can be large — use (default) when listing executions
- Workflow JSON structure follows n8n's internal format (nodes + connections + settings)
Node.js Example
javascript
const N8N_HOST = process.env.N8N_HOST;
const N8N_API_KEY = process.env.N8N_API_KEY;
async function n8nApi(method, path, body = null) {
const url = `${N8N_HOST}/api/v1${path}`;
const options = {
method,
headers: {
'X-N8N-API-KEY': N8N_API_KEY,
'Content-Type': 'application/json',
},
};
if (body) options.body = JSON.stringify(body);
const res = await fetch(url, options);
if (!res.ok) throw new Error(`n8n API ${res.status}: ${await res.text()}`);
return res.json();
}
// List workflows
const workflows = await n8nApi('GET', '/workflows?limit=50');
console.log(workflows.data);
// Create a tag
const tag = await n8nApi('POST', '/tags', { name: 'automated' });
console.log(tag);
Python Example
python
import os
import requests
N8N_HOST = os.environ["N8N_HOST"]
N8N_API_KEY = os.environ["N8N_API_KEY"]
HEADERS = {
"X-N8N-API-KEY": N8N_API_KEY,
"Content-Type": "application/json",
}
def n8n_api(method, path, json=None):
url = f"{N8N_HOST}/api/v1{path}"
resp = requests.request(method, url, headers=HEADERS, json=json)
resp.raise_for_status()
return resp.json()
# List workflows
workflows = n8n_api("GET", "/workflows?limit=50")
for wf in workflows["data"]:
print(f"{wf['id']}: {wf['name']} (active={wf['active']})")
# Create a variable
n8n_api("POST", "/variables", {"key": "ENV", "value": "production"})
Verification
After any API interaction, verify:
- HTTP status code is 2xx
- Response contains expected fields (, , etc.)
- For workflow creation/update: check workflow appears in the list
- For activation: check field is
- For executions: check matches expected outcome
Failure Modes
- 401 Unauthorized: API key is missing, invalid, or expired. Regenerate in n8n UI > Settings > API.
- 404 Not Found: Wrong workflow/execution ID, or the resource was deleted. Verify ID with a list call.
- 400 Bad Request: Invalid JSON body or missing required fields. Check request structure.
- Connection refused: Wrong or n8n instance is down. Verify URL and instance status.
- Empty array: No results match filters. Broaden query parameters.