{
  "name": "Workflow Doctor Preflight Audit",
  "nodes": [
    {
      "parameters": {},
      "id": "manual-trigger",
      "name": "Run audit",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        220,
        260
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "workflow-json",
              "name": "workflowJson",
              "type": "string",
              "value": "{\"name\":\"Example workflow\",\"nodes\":[{\"name\":\"Manual Trigger\",\"type\":\"n8n-nodes-base.manualTrigger\",\"parameters\":{}},{\"name\":\"HTTP Request\",\"type\":\"n8n-nodes-base.httpRequest\",\"parameters\":{\"url\":\"https://example.com\"}}],\"connections\":{},\"settings\":{\"timezone\":\"Europe/Paris\"}}"
            },
            {
              "id": "note",
              "name": "note",
              "type": "string",
              "value": "Replace workflowJson with an exported n8n workflow JSON before running."
            }
          ]
        },
        "options": {}
      },
      "id": "paste-workflow-json",
      "name": "Paste workflow JSON",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        500,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const input = $input.first()?.json || {};\nlet workflow = input.workflow || null;\nif (!workflow && input.workflowJson) {\n  try {\n    const parsed = JSON.parse(input.workflowJson);\n    workflow = parsed.workflow || parsed;\n  } catch (error) {\n    return [{ json: { error: `Invalid workflowJson: ${error.message}` } }];\n  }\n}\nif (!workflow || typeof workflow !== 'object') {\n  return [{ json: { error: 'Missing workflow JSON. Paste an exported n8n workflow into workflowJson.' } }];\n}\nreturn [{ json: { workflow } }];"
      },
      "id": "prepare-payload",
      "name": "Prepare Workflow Doctor payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        780,
        260
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://app.nexus-engine.fr/api/n8n/workflow-doctor",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{$json}}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "send-to-workflow-doctor",
      "name": "Send to Workflow Doctor",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1080,
        260
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "audit-status",
              "name": "auditStatus",
              "type": "string",
              "value": "={{$json.ok ? 'ok' : 'error'}}"
            },
            {
              "id": "workflow-name",
              "name": "workflowName",
              "type": "string",
              "value": "={{$json.data?.workflow?.name || ''}}"
            },
            {
              "id": "score",
              "name": "score",
              "type": "number",
              "value": "={{$json.data?.score || 0}}"
            },
            {
              "id": "issue-count",
              "name": "issueCount",
              "type": "number",
              "value": "={{Array.isArray($json.data?.issues) ? $json.data.issues.length : 0}}"
            },
            {
              "id": "summary",
              "name": "summary",
              "type": "string",
              "value": "={{$json.data?.summary || 'Workflow Doctor response received.'}}"
            },
            {
              "id": "open-full-doctor",
              "name": "openFullDoctor",
              "type": "string",
              "value": "https://app.nexus-engine.fr/workflow-doctor?utm_source=n8nmarkets&utm_medium=workflow&utm_campaign=workflow_doctor_preflight"
            }
          ]
        },
        "options": {}
      },
      "id": "prepare-summary",
      "name": "Prepare audit summary",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1380,
        260
      ]
    }
  ],
  "connections": {
    "Run audit": {
      "main": [
        [
          {
            "node": "Paste workflow JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Paste workflow JSON": {
      "main": [
        [
          {
            "node": "Prepare Workflow Doctor payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Workflow Doctor payload": {
      "main": [
        [
          {
            "node": "Send to Workflow Doctor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to Workflow Doctor": {
      "main": [
        [
          {
            "node": "Prepare audit summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false,
  "pinData": {},
  "versionId": "workflow-doctor-preflight-marketplace-template"
}
