{
  "name": "Nodbot - amoCRM integration blueprint with contact lead upsert",
  "nodes": [
    {
      "parameters": {
        "path": "integration-amocrm-n8n",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "0377d360-d2fb-4d12-941a-b38f775fe097",
      "name": "Webhook input",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst rawPhone = String(src.phone ?? '').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}`;\nif (!/^7\\d{10}$/.test(digits)) throw new Error(`Invalid amoCRM phone: ${rawPhone}`);\nconst email = String(src.email ?? '').trim().toLowerCase();\nconst pipelineId = Number(src.pipeline_id || $env.AMOCRM_DEFAULT_PIPELINE_ID);\nconst statusId = Number(src.status_id || $env.AMOCRM_DEFAULT_STATUS_ID);\nreturn [{ json: {\n  dedupe_key: `amocrm:${digits}:${email || 'no-email'}`,\n  contact: { name: src.name || 'Новый контакт', phone: `+${digits}`, email },\n  lead: {\n    name: `Заявка: ${src.name || '+7 lead'}`,\n    pipeline_id: pipelineId,\n    status_id: statusId,\n    price: Number(src.budget || 0),\n    custom: { utm_source: src.utm_source || '', utm_medium: src.utm_medium || '', utm_campaign: src.utm_campaign || '', external_id: src.external_id || '' }\n  },\n  note: String(src.comment ?? '').slice(0, 2000)\n}}];"
      },
      "id": "11d59a71-8e39-4269-9a54-c738cf5eca81",
      "name": "Normalize amoCRM payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "a2aad08e-2dbb-457a-bd2d-202347b222c6",
      "name": "Find contact and open lead",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "74cf998f-039c-4fb7-a7ad-467a6692192f",
      "name": "Create or update amoCRM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {
        "path": "integration-amocrm-n8n",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "7c88b055-72d3-4c2e-b120-9ca60f5616c7",
      "name": "Webhook loop guard",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "100be219-596c-471d-8853-aad1ae6cde90",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "Webhook input": {
      "main": [
        [
          {
            "node": "Normalize amoCRM payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize amoCRM payload": {
      "main": [
        [
          {
            "node": "Find contact and open lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find contact and open lead": {
      "main": [
        [
          {
            "node": "Create or update amoCRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create or update amoCRM": {
      "main": [
        [
          {
            "node": "Webhook loop guard",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook loop guard": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "integration",
    "production"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "b3e94753-3f56-4610-beaf-472924e69040",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}