{
  "name": "Nodbot - Airtable upsert records with external id",
  "nodes": [
    {
      "parameters": {
        "path": "integration-airtable-n8n-upsert-records",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "a8cb91f9-9ff1-4949-8160-17ebc24ebdc5",
      "name": "Airtable Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst source = String(src.source ?? 'external').trim().toLowerCase();\nconst entityId = String(src.entity_id ?? src.id ?? '').trim();\nif (!entityId) throw new Error('No entity_id for Airtable upsert');\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}`;\nconst email = String(src.email ?? '').trim().toLowerCase();\nconst tags = Array.isArray(src.tags) ? src.tags.map(String).slice(0, 10) : [];\nconst externalId = `${source}:${entityId}`;\nconst filterByFormula = `{External ID} = '${externalId.replace(/'/g, \"\\'\")}'`;\nreturn [{ json: {\n  external_id: externalId,\n  filterByFormula,\n  fields: {\n    'External ID': externalId,\n    'Name': String(src.name ?? 'Новая запись').trim(),\n    'Phone': digits ? `+${digits}` : '',\n    'Email': email,\n    'Status': String(src.status ?? 'new').trim(),\n    'Tags': tags,\n    'Budget': Number(src.budget ?? 0),\n    'Source URL': String(src.source_url ?? '').trim(),\n    'Last synced at': new Date().toISOString(),\n    'Attachments': Array.isArray(src.attachments) ? src.attachments.map(a => ({ url: a.url, filename: a.filename })) : []\n  }\n}}];"
      },
      "id": "953395b7-2d3e-485b-a7c5-f3b895dcb7d2",
      "name": "Normalize Airtable fields",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "7a03f2af-358a-4aa5-a577-cf2a385553ff",
      "name": "Find Airtable record",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "914c6b41-e6cf-4d8b-928f-c8175eab0fd9",
      "name": "Create or update record",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "bd2fcc23-a956-40de-8f89-1974f25b0986",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    }
  ],
  "connections": {
    "Airtable Webhook": {
      "main": [
        [
          {
            "node": "Normalize Airtable fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Airtable fields": {
      "main": [
        [
          {
            "node": "Find Airtable record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Airtable record": {
      "main": [
        [
          {
            "node": "Create or update record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create or update record": {
      "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": "36d9bcec-b89e-4a1f-8ea8-79ed341b36d7",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}