{
  "name": "Nodbot - DaData lead enrichment with quality gate",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "dadata-enrich-lead",
        "responseMode": "responseNode"
      },
      "id": "dadata-enrich-lead-01",
      "name": "Webhook input",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -720,
        40
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst rawPhone = String(src.phone ?? '').trim();\nconst email = String(src.email ?? '').trim().toLowerCase();\nconst name = String(src.name ?? '').trim();\nlet digits = rawPhone.replace(/\\D/g, '');\nif (digits.length === 11 && digits.startsWith('8')) digits = `7${digits.slice(1)}`;\nif (digits.length === 10) digits = `7${digits}`;\nreturn [{ json: {\n  query: {\n    phone: /^7\\d{10}$/.test(digits) ? `+${digits}` : rawPhone,\n    email,\n    name\n  },\n  original: src,\n  dedupe_key: email || digits || src.external_id || `lead:${Date.now()}`\n}}];"
      },
      "id": "dadata-enrich-lead-02",
      "name": "Prepare DaData query",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -440,
        40
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/party",
        "sendBody": true,
        "contentType": "json",
        "bodyParameters": {
          "parameters": []
        }
      },
      "id": "dadata-enrich-lead-03",
      "name": "DaData suggest",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -160,
        40
      ]
    },
    {
      "parameters": {
        "jsCode": "const dadata = $json.suggestions?.[0]?.data ?? $json.data ?? {};\nconst confidence = Number(dadata.qc ?? dadata.qc_geo ?? 99);\nreturn [{ json: {\n  ...$json.original,\n  enriched_name: dadata.name?.result ?? $json.query?.name ?? '',\n  enriched_phone: dadata.phone ?? $json.query?.phone ?? '',\n  region: dadata.region ?? '',\n  quality_code: confidence,\n  enrichment_status: confidence <= 1 ? 'auto_apply' : 'review_needed'\n}}];"
      },
      "id": "dadata-enrich-lead-04",
      "name": "Quality gate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        120,
        40
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://YOUR_CRM_ENDPOINT/leads/update",
        "sendBody": true,
        "contentType": "json",
        "bodyParameters": {
          "parameters": []
        }
      },
      "id": "dadata-enrich-lead-05",
      "name": "Update CRM lead safely",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        400,
        40
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { ok: true, status: \"accepted\" } }}",
        "options": {
          "responseCode": 200
        }
      },
      "id": "dadata-enrich-lead-06",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        680,
        40
      ]
    }
  ],
  "connections": {
    "Webhook input": {
      "main": [
        [
          {
            "node": "Prepare DaData query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare DaData query": {
      "main": [
        [
          {
            "node": "DaData suggest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DaData suggest": {
      "main": [
        [
          {
            "node": "Quality gate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Quality gate": {
      "main": [
        [
          {
            "node": "Update CRM lead safely",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update CRM lead safely": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "nodbot"
    },
    {
      "name": "dadata"
    },
    {
      "name": "enrichment"
    },
    {
      "name": "crm"
    },
    {
      "name": "quality-gate"
    }
  ],
  "triggerCount": 0,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "nodbot-dadata-enrich-lead-problem-solution-v1",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "notes": "Problem/Solution-мануал по обогащению лидов через DaData и n8n: нормализация телефона, ИНН, подсказки по организации, confidence gate, защита CRM от перезаписи хороших данных и production-тесты. Replace credentials, endpoints, IDs and business rules before production."
}