{
  "name": "Owepo — Webhook sécurisé (authentification + validation)",
  "nodes": [
    {
      "id": "n0",
      "name": "Mode d'emploi",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -80
      ],
      "parameters": {
        "content": "## Webhook sécurisé\n1. Créez un credential **Header Auth** (nom : `X-Webhook-Secret`, valeur : une chaîne aléatoire longue).\n2. L'émetteur envoie cet en-tête ; sans lui, n8n répond 403.\n3. Le nœud Code valide les champs attendus : adaptez la liste.\n4. Les données valides partent vers la suite de votre flux ; les autres reçoivent une erreur 400.\n\nModèle offert par Owepo — owepo.com",
        "height": 320,
        "width": 440
      }
    },
    {
      "id": "n1",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "owepo-webhook-securise",
      "parameters": {
        "httpMethod": "POST",
        "path": "entrant",
        "authentication": "headerAuth",
        "responseMode": "responseNode",
        "options": {}
      }
    },
    {
      "id": "n2",
      "name": "Valider",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "jsCode": "const b = $input.first().json.body || {};\nconst requis = ['email']; // champs obligatoires\nconst manquants = requis.filter(k => !b[k] || typeof b[k] !== 'string');\nconst emailOk = typeof b.email === 'string' && /^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(b.email);\nconst s = v => typeof v === 'string' ? v.trim().slice(0, 2000) : v;\nconst propre = Object.fromEntries(Object.entries(b).slice(0, 50).map(([k, v]) => [k, s(v)]));\nreturn [{ json: { valide: !manquants.length && emailOk, manquants, donnees: propre } }];"
      }
    },
    {
      "id": "n3",
      "name": "Valide ?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        480,
        300
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.valide }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "n4",
      "name": "Répondre 200",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        720,
        200
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { ok: true } }}",
        "options": {
          "responseCode": 200
        }
      }
    },
    {
      "id": "n5",
      "name": "Répondre 400",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        720,
        400
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { ok: false, manquants: $json.manquants } }}",
        "options": {
          "responseCode": 400
        }
      }
    },
    {
      "id": "n6",
      "name": "Suite du traitement",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        960,
        200
      ],
      "parameters": {}
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Valider",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Valider": {
      "main": [
        [
          {
            "node": "Valide ?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Valide ?": {
      "main": [
        [
          {
            "node": "Répondre 200",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Répondre 400",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Répondre 200": {
      "main": [
        [
          {
            "node": "Suite du traitement",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveDataErrorExecution": "all",
    "executionTimeout": 120
  },
  "pinData": {}
}