{
  "name": "Nodbot - HubSpot contact and deal sync with dedupe",
  "nodes": [
    {
      "parameters": {
        "path": "integration-hubspot-n8n-contact-deal-sync",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "1e279e4c-9151-46e3-8d04-f3954b46f790",
      "name": "HubSpot Lead Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst email = String(src.email ?? '').trim().toLowerCase();\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 (!email && !digits) throw new Error('HubSpot contact needs email or phone');\nconst eventId = String(src.event_id ?? src.order_id ?? '').trim();\nif (!eventId) throw new Error('No event_id for HubSpot sync');\nconst contactKey = email || `phone:+${digits}`;\nconst dealKey = `hubspot-deal:${eventId}`;\nreturn [{ json: {\n  contact_key: contactKey,\n  deal_key: dealKey,\n  contact_properties: {\n    email,\n    phone: digits ? `+${digits}` : '',\n    firstname: String(src.firstname ?? src.name ?? '').trim(),\n    lastname: String(src.lastname ?? '').trim(),\n    company: String(src.company ?? '').trim(),\n    lifecyclestage: 'lead',\n    hs_analytics_source: String(src.utm_source ?? '').trim()\n  },\n  deal_properties: {\n    dealname: String(src.deal_name ?? `Заявка ${eventId}`).trim(),\n    amount: Number(src.amount ?? 0),\n    pipeline: String(src.pipeline ?? 'default').trim(),\n    dealstage: String(src.dealstage ?? '').trim(),\n    description: `Source: ${src.source_url ?? ''}; campaign: ${src.utm_campaign ?? ''}`\n  },\n  idempotency_key: `hubspot:${eventId}`\n}}];"
      },
      "id": "aa465064-08a0-445b-8c01-3c5fdfa0438e",
      "name": "Normalize HubSpot fields",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "e508e6ba-e9b7-4aea-8983-79c264122ad8",
      "name": "Search HubSpot contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "a0fcd86a-0a57-408e-9581-15f04579aa47",
      "name": "Upsert contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "b0efae51-5177-4c6f-becc-b069bae6d7aa",
      "name": "Create and associate deal",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "e4bfcd20-cd84-4141-8a3b-d821112cc67a",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "HubSpot Lead Webhook": {
      "main": [
        [
          {
            "node": "Normalize HubSpot fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize HubSpot fields": {
      "main": [
        [
          {
            "node": "Search HubSpot contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search HubSpot contact": {
      "main": [
        [
          {
            "node": "Upsert contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert contact": {
      "main": [
        [
          {
            "node": "Create and associate deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create and associate deal": {
      "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": "f62bbaec-900a-45dd-84bd-16245015af71",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}