{
  "name": "Create Dynamic Workflows Programmatically via Webhooks & n8n API",
  "nodes": [
    {
      "id": "41cfbc58-c8d5-4a22-aec1-72a4b7db3d63",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2360,
        -2100
      ],
      "parameters": {
        "width": 720,
        "height": 500,
        "content": "1. **Webhook**: it receives a POST at `/webhook/create-workflow` with the workflow JSON.\n2. **Validate JSON**: it runs code that checks the JSON has the fields `name` and `nodes`, and that each node h"
      }
    },
    {
      "id": "62c4a402-1397-4aad-82de-c38672a382a7",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1600,
        -1740
      ],
      "parameters": {
        "width": 820,
        "height": 360,
        "content": "1. **Validation Error**: Sets a JSON response with `success: false` and uses the incoming `$json.message` as the error message when the initial payload validation fails.\n\n2. **API Error**: Sets a JSON"
      }
    },
    {
      "id": "df771acf-ef37-49f9-8a9f-ec60fd955d86",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1520,
        -2320
      ],
      "parameters": {
        "width": 720,
        "height": 500,
        "content": "1. **Create Workflow**: Sends a POST to `/api/v1/workflows` with the validated workflow payload, using header-based authentication.\n2. **API Successful?**: Checks if the HTTP response status code is ≤"
      }
    },
    {
      "id": "c798d2a9-577d-4f46-b269-ca2b4447560c",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2280,
        -1880
      ]
    },
    {
      "id": "3ca95b00-83b2-4f75-874f-43a27e298bf1",
      "name": "Validate JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        -2060,
        -1880
      ]
    },
    {
      "id": "b3894755-0583-4c00-b574-e993a6f0b08f",
      "name": "Validation Successful?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1840,
        -1880
      ]
    },
    {
      "id": "ef3a310b-7673-40cc-985a-4e87dc99de70",
      "name": "Create Workflow",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1440,
        -2080
      ]
    },
    {
      "id": "7e2c1a11-1d4c-4075-a03c-f6ed93307d19",
      "name": "API Successful?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1220,
        -2080
      ]
    },
    {
      "id": "0371ce73-ccb6-4e87-8620-4aab8529b170",
      "name": "Success Response",
      "type": "n8n-nodes-base.set",
      "position": [
        -960,
        -2180
      ]
    },
    {
      "id": "daec93d7-b9d8-4407-93ab-389b705b0c11",
      "name": "Validation Error",
      "type": "n8n-nodes-base.set",
      "position": [
        -1500,
        -1540
      ]
    },
    {
      "id": "cd2cd403-63c2-42af-a715-9f080067f7d1",
      "name": "API Error",
      "type": "n8n-nodes-base.set",
      "position": [
        -920,
        -1540
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Validate JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate JSON": {
      "main": [
        [
          {
            "node": "Validation Successful?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API Successful?": {
      "main": [
        [
          {
            "node": "Success Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "API Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Workflow": {
      "main": [
        [
          {
            "node": "API Successful?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validation Successful?": {
      "main": [
        [
          {
            "node": "Create Workflow",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Validation Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}