Skip to main content

Create Dynamic Workflows Programmatically via Webhooks & n8n API

Workflow preview

Workflow preview
100%
Create Dynamic Workflows Programmatically via Webhooks & n8n API preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

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 ...

Best for

  • DevOps automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

n8n-nodes-base.stickynote, n8n-nodes-base.webhook, n8n-nodes-base.code, n8n-nodes-base.if, n8n-nodes-base.httprequest, n8n-nodes-base.set

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Mauricio Perera.

Original n8n.io source

1.1 Workflow description

Title
Create Dynamic Workflows Programmatically via Webhooks & n8n API
Workflow name
Create Dynamic Workflows Programmatically via Webhooks & n8n API

Overview

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.

Workflow Diagram

Webhook
   │
   ▼
Validate JSON ── fails validation ──► Validation Error
   │
   └─ passes ─► Validation Successful?
                           │
                           ├─ true ─► Create Workflow ──► API Successful? ──► Success Response
                           │                                 │
                           │                                 └─ false ─► API Error
                           └─ false ─► Validation Error

Step-by-Step Details

1. Webhook

  • Type: Webhook (POST)
  • Path: /webhook/create-workflow
  • Purpose: Expose a URL to receive a JSON definition of a workflow.
  • Expected Input: JSON containing the main workflow fields (name, nodes, connections, settings).

2. Validate JSON

  • Type: Code Node (JavaScript)

  • Validations Performed:

    • Ensure that payload exists and contains both name and nodes.
    • Verify that nodes is an array with at least one item.
    • Check that each node includes the required fields: id, name, type, position.
    • If missing, initialize 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
      }
    }
    

3. Validation Successful?

  • Type: IF Node

  • Condition: $json.success === true

  • Branches:

    • true: proceed to Create Workflow
    • false: route to Validation Error

4. Create Workflow

  • Type: HTTP Request (POST)
  • URL: http://127.0.0.1:5678/api/v1/workflows
  • Authentication: Header Auth with internal credentials
  • Body: The apiWorkflow object generated earlier
  • Options: continueOnFail: true (to handle failures in the next IF)

5. API Successful?

  • Type: IF Node

  • Condition: $response.statusCode <= 299

  • Branches:

    • true: proceed to Success Response
    • false: route to API Error

6. Success Response

  • 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 }}"
    }
    

7. API Error

  • Type: SET Node

  • Output:

    {
      "success": "false",
      "message": "Error creating workflow",
      "error": "{{ JSON.stringify($json) }}",
      "statusCode": "{{ $response.statusCode }}"
    }
    

8. Validation Error

  • Type: SET Node

  • Output:

    { "success": false, "message": "{{ $json.message }}" }
    

Example Webhook Request

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": {}
}'

Expected Success Response

{
  "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"
}

Validation Error Response

{
  "success": false,
  "message": "The 'name' field is required in the workflow"
}

API Error Response

{
  "success": "false",
  "message": "Error creating workflow",
  "error": "{ ...full API response details... }",
  "statusCode": 401
}

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 2 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 3 - Sticky Note7

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 1

Block 5 - Validate JSON

Type / Role
n8n-nodes-base.code - code
Config choices
Version 1

Block 6 - Validation Successful?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 1

Block 7 - Create Workflow

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 1

Block 8 - API Successful?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 1

Block 9 - Success Response

Type / Role
n8n-nodes-base.set - set
Config choices
Version 1

Block 10 - Validation Error

Type / Role
n8n-nodes-base.set - set
Config choices
Version 1

Block 11 - API Error

Type / Role
n8n-nodes-base.set - set
Config choices
Version 1

3. Summary Table

Workflow Create Dynamic Workflows Programmatically via Webhooks & n8n API
Complexity intermediate
Nodes 11
Categories DevOps
Author Mauricio Perera
Published 01 Jun 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/4544/4544.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Create Dynamic Workflows Programmatically via Webhooks & n8n API do?

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 ...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your DevOps use case.