Back to Templates
This workflow exposes an HTTP endpoint (webhook) that accepts a JSON definition of an n8n workflow, validates it, and—if everything is correct—dynamically creates that workflow in the n8n instance via its internal API. If any validation fails or the API call encounters an error, an explanatory message with details is returned.
Webhook
│
▼
Validate JSON ── fails validation ──► Validation Error
│
└─ passes ─► Validation Successful?
│
├─ true ─► Create Workflow ──► API Successful? ──► Success Response
│ │
│ └─ false ─► API Error
└─ false ─► Validation Error
/webhook/create-workflow
name
, nodes
, connections
, settings
).Type: Code Node (JavaScript)
Validations Performed:
payload
exists and contains both name
and nodes
.nodes
is an array with at least one item.id
, name
, type
, position
.connections
, settings
, parameters
, and typeVersion
.Output if Error:
{ "success": false, "message": "<error description>" }
Output if Valid:
{
"success": true,
"apiWorkflow": {
"name": payload.name,
"nodes": payload.nodes,
"connections": payload.connections,
"settings": payload.settings
}
}
Type: IF Node
Condition: $json.success === true
Branches:
http://127.0.0.1:5678/api/v1/workflows
apiWorkflow
object generated earliercontinueOnFail: true
(to handle failures in the next IF)Type: IF Node
Condition: $response.statusCode <= 299
Branches:
Type: SET Node
Output:
{
"success": "true",
"message": "Workflow created successfully",
"workflowId": "{{ $json.data[0].id }}",
"workflowName": "{{ $json.data[0].name }}",
"createdAt": "{{ $json.data[0].createdAt }}",
"url": "http://localhost:5678/workflow/{{ $json.data[0].id }}"
}
Type: SET Node
Output:
{
"success": "false",
"message": "Error creating workflow",
"error": "{{ JSON.stringify($json) }}",
"statusCode": "{{ $response.statusCode }}"
}
Type: SET Node
Output:
{ "success": false, "message": "{{ $json.message }}" }
curl --location --request POST 'http://localhost:5678/webhook/create-workflow' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "My Dynamic Workflow",
"nodes": [
{
"id": "start-node",
"name": "Start",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [100, 100],
"parameters": {}
},
{
"id": "set-node",
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [300, 100],
"parameters": {
"values": {
"string": [
{ "name": "message", "value": "Hello from a webhook-created workflow!" }
]
}
}
}
],
"connections": {
"Start": {
"main": [
[ { "node": "Set", "type": "main", "index": 0 } ]
]
}
},
"settings": {}
}'
{
"success": "true",
"message": "Workflow created successfully",
"workflowId": "abcdef1234567890",
"workflowName": "My Dynamic Workflow",
"createdAt": "2025-05-31T12:34:56.789Z",
"url": "http://localhost:5678/workflow/abcdef1234567890"
}
{
"success": false,
"message": "The 'name' field is required in the workflow"
}
{
"success": "false",
"message": "Error creating workflow",
"error": "{ ...full API response details... }",
"statusCode": 401
}