{ "name": "[1604][Bucéfalo] Monte Providencia - Crear Contacto - MARCA A SUCURSAL V2", "nodes": [ { "parameters": { "content": "# Monte Providencia - Ingesta de datos", "height": 352, "width": 592 }, "type": "n8n-nodes-base.stickyNote", "position": [ -1568, 496 ], "typeVersion": 1, "id": "c193406b-0aaf-474d-9716-175c1b526321", "name": "Sticky Note2" }, { "parameters": { "httpMethod": "POST", "path": "8d16dc55-616a-4532-8334-8ac81e7d3ae1", "options": {} }, "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ -1568, 624 ], "id": "80dba2db-7b6d-446c-9d22-828a7f7093db", "name": "Webhook", "webhookId": "8d16dc55-616a-4532-8334-8ac81e7d3ae1" }, { "parameters": { "content": "# De Marca a Sucursal", "color": 5 }, "type": "n8n-nodes-base.stickyNote", "position": [ -1872, 592 ], "typeVersion": 1, "id": "54adaeec-43eb-4f9f-86fd-d1157aa315d6", "name": "Sticky Note3" }, { "parameters": { "content": "", "height": 176, "width": 592, "color": 7 }, "type": "n8n-nodes-base.stickyNote", "position": [ 2624, 608 ], "typeVersion": 1, "id": "75c1aa76-ce43-4ac3-b31b-02fa9ad0f9df", "name": "Sticky Note4" }, { "parameters": { "content": "# REVISIÓN SIEMPRE", "height": 240, "width": 352, "color": 3 }, "type": "n8n-nodes-base.stickyNote", "position": [ 592, 544 ], "typeVersion": 1, "id": "e74e61fd-6560-46b1-a343-0fae6eb76b85", "name": "Sticky Note5" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "91e3e213-9797-4be0-85d5-480bd1a9510c", "leftValue": "={{ $json.contacts[1] }}", "rightValue": "", "operator": { "type": "object", "operation": "exists", "singleValue": true } }, { "id": "01b8ad0c-ac85-470e-a82d-205b5688e5a5", "leftValue": "={{ $json.total }}", "rightValue": 0, "operator": { "type": "number", "operation": "gt" } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ 1632, 608 ], "id": "807101d9-ebe6-47c7-b9bb-f3820e491953", "name": "Si hay más de un resultado" }, { "parameters": { "databaseId": 63, "tableId": 749, "additionalOptions": { "filters": { "fields": [ { "field": 7235, "value": "={{ $('Datos de Lead2').item.json.Sucursal['Cuenta Bucéfalo'] }}" } ] } } }, "type": "n8n-nodes-base.baserow", "typeVersion": 1, "position": [ -704, 608 ], "id": "f404375d-5d42-4064-a7e1-94a445986256", "name": "Obtener Info de cuenta origen - MARCA", "credentials": { "baserowApi": { "id": "LZztQ3WMpzXjSTIH", "name": "Baserow account" } } }, { "parameters": { "databaseId": 63, "tableId": 750, "limit": 3, "additionalOptions": { "filters": { "fields": [ { "field": 7240, "operator": "contains", "value": "={{ $json.Contacto.Sucursal }}" } ] } } }, "type": "n8n-nodes-base.baserow", "typeVersion": 1, "position": [ 1008, 608 ], "id": "a02f5dc5-28c9-4b52-830e-62f93c7af679", "name": "Obtener Info de cuenta objetivo - SUCURSAL", "credentials": { "baserowApi": { "id": "LZztQ3WMpzXjSTIH", "name": "Baserow account" } } }, { "parameters": { "method": "POST", "url": "https://services.leadconnectorhq.com/contacts/search", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $json['Token/API'] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"locationId\": \"{{ $json['ID LOCATION BUCEFALO'] }}\",\n \"pageLimit\": 20,\n \"query\":\"{{ $('DATOS CUENTA A CHECAR').item.json.Contacto.email }}\"\n}", "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 1376, 608 ], "id": "d121ac1d-8b43-48fa-8155-1d97c6a32131", "name": "Buscar Contacto Objetivo - SUCURSAL(mail)", "alwaysOutputData": true, "onError": "continueRegularOutput" }, { "parameters": { "method": "POST", "url": "https://services.leadconnectorhq.com/contacts/search", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['Token/API'] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"locationId\": \"{{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['ID LOCATION BUCEFALO'] }}\",\n \"pageLimit\": 20,\n \"query\":\"{{ $('Datos de Lead2').item.json.Cliente.Telefono }}\"\n}", "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 1792, 432 ], "id": "5870bc85-4f55-4287-aaed-ad84aecf65ac", "name": "Retry - Buscar Contacto Objetivo - SUCURSAL (teléfono)" }, { "parameters": { "method": "POST", "url": "https://services.leadconnectorhq.com/contacts/search", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['Token/API'] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"locationId\": \"{{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['ID LOCATION BUCEFALO'] }}\",\n \"pageLimit\": 20,\n \"query\": \"{{ $('Datos de Lead2').item.json.Cliente['Nombre Completo'] }}\"\n}", "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 2304, 416 ], "id": "855a8f25-5291-4411-9eea-e9e596a3433c", "name": "Retry - Buscar Contacto Objetivo - SUCURSAL (nombre)" }, { "parameters": { "url": "=https://services.leadconnectorhq.com/locations/{{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['ID LOCATION BUCEFALO'] }}/customFields", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/json" }, { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['Token/API'] }}" } ] }, "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 3216, 480 ], "id": "afa5711f-0fb0-4d0b-b7f9-87c50a3c6767", "name": "Conseguir Custom Cuenta objetivo - SUCURSAL" }, { "parameters": { "jsCode": "// Inputs\nconst contactData = $('Obtener Contacto Cuenta objetivo - SUCURSAL').first().json.contact;\nconst allCustomFieldItems = $('Conseguir Custom Cuenta objetivo - SUCURSAL').all();\n\n// Consolidar TODOS los customFields de todos los items del nodo\nconst allFieldDefs = [];\nfor (const item of allCustomFieldItems) {\n const fields = item.json.customFields || [];\n allFieldDefs.push(...fields);\n}\n\n// Crear mapa id -> definición completa\nconst fieldKeyMap = {};\nfor (const field of allFieldDefs) {\n fieldKeyMap[field.id] = {\n fieldKey: field.fieldKey,\n name: field.name,\n dataType: field.dataType\n };\n}\n\n// Enriquecer los customFields del contacto con su fieldKey\nconst enrichedCustomFields = [];\nfor (const cf of contactData.customFields) {\n const def = fieldKeyMap[cf.id];\n if (def) {\n enrichedCustomFields.push({\n id: cf.id,\n fieldKey: def.fieldKey,\n name: def.name,\n dataType: def.dataType,\n value: cf.value\n });\n } else {\n // Campo sin definición encontrada — se conserva con id para no perder datos\n enrichedCustomFields.push({\n id: cf.id,\n fieldKey: null,\n name: null,\n dataType: null,\n value: cf.value\n });\n }\n}\n\n// Construir objeto de contacto completo\nconst contactoOrigen = {\n id: contactData.id,\n firstName: contactData.firstName,\n lastName: contactData.lastName,\n email: contactData.email,\n country: contactData.country,\n locationId: contactData.locationId,\n type: contactData.type,\n tags: contactData.tags,\n dateAdded: contactData.dateAdded,\n dateUpdated: contactData.dateUpdated,\n additionalEmails: contactData.additionalEmails,\n additionalPhones: contactData.additionalPhones,\n customFields: enrichedCustomFields\n};\n\nreturn [{ json: contactoOrigen }];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3392, 480 ], "id": "48aba134-dd42-429f-acc0-363ef045dba9", "name": "Obtener datos completos de Contacto objetivo - SUCURSAL" }, { "parameters": { "jsCode": "var origenRaw = $('Obtener Contacto Cuenta Origen - SUCURSAL').first().json.contact; // campos estandar (crudo)\nvar origenData = $('Obtener datos completos de Contacto origen - SUCURSAL').first().json; // custom fields enriquecidos\nvar objetivoData = $('Obtener datos completos de Contacto objetivo - SUCURSAL').first().json;\n\n// Custom fields: mapeo por fieldKey (origen -> objetivo), usando el id del objetivo\nvar customFields = [];\nvar oCF = origenData.customFields;\nvar tCF = objetivoData.customFields;\nif (Array.isArray(oCF) && Array.isArray(tCF)) {\n for (var i = 0; i < oCF.length; i++) {\n var campoOrigen = oCF[i];\n if (!campoOrigen.fieldKey) continue;\n var campoObjetivo = null;\n for (var j = 0; j < tCF.length; j++) {\n if (tCF[j].fieldKey === campoOrigen.fieldKey) { campoObjetivo = tCF[j]; break; }\n }\n if (!campoObjetivo) continue;\n var rawValue = campoOrigen.value;\n var fieldValue = Array.isArray(rawValue) ? rawValue : (rawValue !== undefined ? rawValue : null);\n customFields.push({ id: campoObjetivo.id, key: campoObjetivo.fieldKey, field_value: fieldValue });\n }\n}\n\n// Campos estandar desde el contacto crudo (allowlist). NO se envia locationId (es PUT).\nvar STANDARD = ['firstName','lastName','email','phone','address1','city','state','country','postalCode','dateOfBirth','companyName','website','timezone','source','type','dnd'];\nvar body = { customFields: customFields };\nfor (var k = 0; k < STANDARD.length; k++) {\n var f = STANDARD[k];\n var val = origenRaw[f];\n if (val !== undefined && val !== null && val !== '') body[f] = val;\n}\nbody.tags = (origenRaw.tags && origenRaw.tags.length > 0) ? origenRaw.tags : [];\n\nreturn [{ json: { body: JSON.stringify(body) } }];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3600, 480 ], "id": "a0d5096f-24dd-4846-9f94-e93099cda787", "name": "Obtener Body para Actualizar Contacto Objetivo - SUCURSAL" }, { "parameters": { "method": "PUT", "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Obtener Contacto Cuenta objetivo - SUCURSAL').item.json.contact.id }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/json" }, { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['Token/API'] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ $json.body }}", "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 3792, 480 ], "id": "fba1aee4-9bed-4272-8169-d6ee64f6f7bb", "name": "Actualizar Contacto Cuenta Objetivo - SUCURSAL" }, { "parameters": { "url": "=https://services.leadconnectorhq.com/locations/{{ $('Datos API Cuenta Origen').item.json['Location ID'] }}/customFields", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/json" }, { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $('Datos API Cuenta Origen').item.json['Token/API'] }}" } ] }, "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ -16, 608 ], "id": "8e4e5825-9ff9-4e88-8b50-26a7f601cbea", "name": "Conseguir Custom Cuenta Origen- SUCURSAL" }, { "parameters": { "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Datos de Lead2').item.json.Cliente['Contact ID'] }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/json" }, { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $json['Token/API'] }}" } ] }, "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ -192, 608 ], "id": "29bf86c1-52ec-4ff6-9bbb-3033ad1b1bfe", "name": "Obtener Contacto Cuenta Origen - SUCURSAL" }, { "parameters": { "jsCode": "// Inputs\nconst contactData = $('Obtener Contacto Cuenta Origen - SUCURSAL').first().json.contact;\nconst allCustomFieldItems = $('Conseguir Custom Cuenta Origen- SUCURSAL').all();\n\n// Consolidar TODOS los customFields de todos los items del nodo\nconst allFieldDefs = [];\nfor (const item of allCustomFieldItems) {\n const fields = item.json.customFields || [];\n allFieldDefs.push(...fields);\n}\n\n// Crear mapa id -> definición completa\nconst fieldKeyMap = {};\nfor (const field of allFieldDefs) {\n fieldKeyMap[field.id] = {\n fieldKey: field.fieldKey,\n name: field.name,\n dataType: field.dataType\n };\n}\n\n// Enriquecer los customFields del contacto con su fieldKey\nconst enrichedCustomFields = [];\nfor (const cf of contactData.customFields) {\n const def = fieldKeyMap[cf.id];\n if (def) {\n enrichedCustomFields.push({\n id: cf.id,\n fieldKey: def.fieldKey,\n name: def.name,\n dataType: def.dataType,\n value: cf.value\n });\n } else {\n // Campo sin definición encontrada — se conserva con id para no perder datos\n enrichedCustomFields.push({\n id: cf.id,\n fieldKey: null,\n name: null,\n dataType: null,\n value: cf.value\n });\n }\n}\n\n// Construir objeto de contacto completo\nconst contactoOrigen = {\n id: contactData.id,\n firstName: contactData.firstName,\n lastName: contactData.lastName,\n email: contactData.email,\n country: contactData.country,\n locationId: contactData.locationId,\n type: contactData.type,\n tags: contactData.tags,\n dateAdded: contactData.dateAdded,\n dateUpdated: contactData.dateUpdated,\n additionalEmails: contactData.additionalEmails,\n additionalPhones: contactData.additionalPhones,\n customFields: enrichedCustomFields\n};\n\nreturn [{ json: contactoOrigen }];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 192, 608 ], "id": "ba139309-3eb2-4f0d-a21f-a52155191a7a", "name": "Obtener datos completos de Contacto origen - SUCURSAL" }, { "parameters": { "url": "=https://services.leadconnectorhq.com/locations/{{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['ID LOCATION BUCEFALO'] }}/customFields", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/json" }, { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['Token/API'] }}" } ] }, "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 3248, 848 ], "id": "29bc890a-201a-42da-96ce-cda74fc1b1e1", "name": "Conseguir Custom Cuenta objetivo - MARCA1" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "325cb1d8-a045-45a6-a8b1-aca5f6c1f1c4", "leftValue": "={{ $json.contact.id }}", "rightValue": "AxiosError", "operator": { "type": "string", "operation": "exists", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ 2960, 624 ], "id": "249f37e8-0e0f-4a44-a5ec-30bd210f9ce6", "name": "Verificar Existencia de Contcato" }, { "parameters": { "method": "POST", "url": "=https://services.leadconnectorhq.com/contacts", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/json" }, { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['Token/API'] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ $json.body }}", "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 3744, 848 ], "id": "7cc04e8f-0939-4f12-8f3e-df563193dc79", "name": "Crear Contacto - Cuenta Objetivo - MARCA" }, { "parameters": { "url": "=https://services.leadconnectorhq.com/contacts/{{ $json.contacts[0].id }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "application/json" }, { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['Token/API'] }}" } ] }, "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 2672, 640 ], "id": "a47cbdbf-65bd-47cd-851b-89cd2315ccb9", "name": "Obtener Contacto Cuenta objetivo - SUCURSAL", "alwaysOutputData": true, "onError": "continueRegularOutput" }, { "parameters": { "assignments": { "assignments": [ { "id": "55ff7d12-17b9-4bec-a324-e633020b131d", "name": "Name Location", "value": "={{ $('Obtener Info de cuenta origen - MARCA').item.json.Nombre }}", "type": "string" }, { "id": "d877c8cd-db32-4c16-96dd-4eeb2dc48efe", "name": "Location ID", "value": "={{ $('Obtener Info de cuenta origen - MARCA').item.json.Location_ID }}", "type": "string" }, { "id": "7698f395-5db8-415b-919e-3ad61c6566f8", "name": "Token/API", "value": "={{ $('Obtener Info de cuenta origen - MARCA').item.json.API_token }}", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ -512, 608 ], "id": "5c05d6df-cd8a-4e0c-80f2-9fdafd7db9e7", "name": "Datos API Cuenta Origen", "notes": "Esta en modo prueba forzada para Queretaro" }, { "parameters": { "assignments": { "assignments": [ { "id": "f8e50b58-6bb5-4879-b60e-7d23e6a91776", "name": "Marca.Nombre de cuenta", "value": "Monte Providencia", "type": "string" }, { "id": "61d28849-1504-476d-b754-1ae255fc9a12", "name": "Contacto.Nombre", "value": "={{ $json.firstName }}", "type": "string" }, { "id": "096deddd-c321-42b6-a36c-94271101a41c", "name": "Contacto.Apellidos", "value": "={{ $json.lastName }}", "type": "string" }, { "id": "9171bd91-7d9c-4f44-8fd4-0a18c738a205", "name": "Contacto.email", "value": "={{ $json.email }}", "type": "string" }, { "id": "f5008e38-c604-433f-86c7-efcaa90f908b", "name": "Contacto.Sucursal", "value": "={{ $('Datos de Lead2').item.json.Cliente.Sucursal.Sucursal }}", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 720, 608 ], "id": "2a7f7ac0-c38d-4cc9-a41f-ba261eb6a71b", "name": "DATOS CUENTA A CHECAR" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "44d54b9e-d192-4b54-bf0c-156b79afc6e2", "leftValue": "={{ $json.Cliente.Email }}", "rightValue": "@ezcorp.com", "operator": { "type": "string", "operation": "notContains" } }, { "id": "317268c1-9c8c-4d09-829e-a791534c0ea5", "leftValue": "={{ $json.Cliente.Sucursal.Sucursal }}", "rightValue": "=[empty]", "operator": { "type": "string", "operation": "notEquals" } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ -1184, 624 ], "id": "1c5c8848-9ceb-47f0-a102-4a87d9495f55", "name": "Omitir @ezcorp.com2" }, { "parameters": { "assignments": { "assignments": [ { "id": "8a998fd4-2de6-4895-ab3d-e052e823d1b8", "name": "Cliente.Fuente Posible Cliente", "value": "={{ $json.body['Fuente de Posible cliente'] }}", "type": "string" }, { "id": "938c6fec-ae16-4e7a-ba2a-f450794fa40d", "name": "Cliente.Fecha de creación", "value": "={{ $json.body.date_created }}", "type": "string" }, { "id": "b56a1939-2608-47c8-85ad-b60b557d2a27", "name": "Cliente.Sucursal.Sucursal", "value": "={{ $json.body.Sucursal }}", "type": "string" }, { "id": "0d07b9c9-4450-497b-ab81-3baa441787fb", "name": "Vehiculo.Versión.Versión", "value": "={{ $json.body['Version del Vehiculo'] }}", "type": "string" }, { "id": "75e3f337-00d1-429d-8d5b-85ec18e6c5e4", "name": "Vehiculo.Marca.Marca", "value": "={{ $json.body['Marca del Vehiculo'] }}", "type": "string" }, { "id": "cb09c536-fe84-4598-aaae-aa79f2eda61b", "name": "Vehiculo.Marca.fieldKey", "value": "=contact.marca_del_vehiculo", "type": "string" }, { "id": "17d36409-4c54-48dd-8100-f7f667fd2415", "name": "Vehiculo.Año.Año", "value": "={{ $json.body['Año del Vehículo'] }}", "type": "string" }, { "id": "a1886afc-b0af-4950-9752-f8bfff594896", "name": "Vehiculo.Modalidad.Modalidad", "value": "={{ $json.body['¿Qué modalidad prefieres?'] }}", "type": "string" }, { "id": "33b2c28a-1ad3-4c74-917f-3cd718a3a709", "name": "Cliente.Nombre", "value": "={{ $json.body['Información Adicional'] }}", "type": "string" }, { "id": "b36131ac-2d88-41f8-8f0f-7640cdb02b57", "name": "Cliente.Apellido", "value": "={{ $json.body.first_name }}", "type": "string" }, { "id": "ae252c8f-f0a1-41d9-a21d-04ca949f01c8", "name": "Cliente.Nombre Completo", "value": "={{ $json.body.full_name }}", "type": "string" }, { "id": "342a9377-0ded-4f23-b93b-1f76e57c0cbd", "name": "Cliente.Email", "value": "={{ $json.body.email }}", "type": "string" }, { "id": "cf1b7058-96c2-4c73-9250-719a88b68673", "name": "Cliente.Telefono", "value": "={{ $json.body.phone }}", "type": "string" }, { "id": "0b916193-15e8-4a91-9ff2-0a6f262b3c38", "name": "Cliente.Contact ID", "value": "={{ $json.body.contact_id }}", "type": "string" }, { "id": "67eeaa9b-f703-4521-82af-9d2797131edc", "name": "Cliente.Sucursal.fieldKey", "value": "contact.sucursal", "type": "string" }, { "id": "b05ea7bb-bbaa-467b-8247-eabb162ff029", "name": "Vehiculo.Versión.fieldKey", "value": "contact.version_del_vehiculo", "type": "string" }, { "id": "9891b919-ef4c-46bd-8414-6d916565d896", "name": "Vehiculo.Año.fieldKey", "value": "contact.ano_del_vehiculo", "type": "string" }, { "id": "0b6bf582-49c1-41de-9c2e-6ae85c4e41e8", "name": "Vehiculo.Modalidad.fieldKey", "value": "contact.que_modalidad_prefieres", "type": "string" }, { "id": "57199999-2d9b-41c7-8269-5a8183ca8132", "name": "Cliente.Cuándo necesitas el dinero", "value": "={{ $json.body[\"¿Cuándo necesitas el dinero?\"] }}", "type": "string" }, { "id": "8060d06e-b1da-4a65-8a0a-3c21d237d77e", "name": "Sucursal.Cuenta Bucéfalo", "value": "={{ $json.body.location.name }}", "type": "string" }, { "id": "e60a3b0d-e168-4708-ad70-70e25b9f3883", "name": "Dominio API CRM", "value": "https://crm.bucefalocrm.io/v2/location/", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ -1360, 624 ], "id": "657d8486-e6cf-4059-a186-cbe6ff1572f4", "name": "Datos de Lead2" }, { "parameters": { "content": "# CUENTA ORIGEN", "height": 240, "width": 1344 }, "type": "n8n-nodes-base.stickyNote", "position": [ -768, 544 ], "typeVersion": 1, "id": "53c2abf5-2cda-4d84-ba90-9e952bedae40", "name": "Sticky Note6" }, { "parameters": { "content": "", "height": 176, "width": 608, "color": 7 }, "type": "n8n-nodes-base.stickyNote", "position": [ -240, 592 ], "typeVersion": 1, "id": "9613de55-92a8-4735-b5be-7d1115b28551", "name": "Sticky Note7" }, { "parameters": { "content": "# CUENTA OBJETIVO", "height": 240, "width": 1632 }, "type": "n8n-nodes-base.stickyNote", "position": [ 960, 544 ], "typeVersion": 1, "id": "03da198e-5b3f-4695-9fbd-b73d6030a55b", "name": "Sticky Note8" }, { "parameters": { "jsCode": "var origenData = $('Obtener Contacto Cuenta Origen - SUCURSAL').first().json.contact;\nvar marcaCustomDefs = $('Conseguir Custom Cuenta objetivo - MARCA1').first().json.customFields;\nvar origenDefs = $('Conseguir Custom Cuenta Origen- SUCURSAL').first().json.customFields;\nvar locationId = $('Datos API Cuenta objetivo - SUCURSAL').first().json['ID LOCATION BUCEFALO'];\n\n// Custom fields: mapeo 100% dinamico por fieldKey (origen -> destino)\nvar idToFieldKey = {};\nfor (var i = 0; i < origenDefs.length; i++) {\n idToFieldKey[origenDefs[i].id] = origenDefs[i].fieldKey;\n}\nvar valoresPorFieldKey = {};\nfor (var i = 0; i < origenData.customFields.length; i++) {\n var cf = origenData.customFields[i];\n var fk = idToFieldKey[cf.id];\n if (fk) valoresPorFieldKey[fk] = cf.value;\n}\nvar customFields = [];\nfor (var j = 0; j < marcaCustomDefs.length; j++) {\n var def = marcaCustomDefs[j];\n var rawValue = valoresPorFieldKey[def.fieldKey];\n if (rawValue !== undefined && rawValue !== null) {\n customFields.push({ id: def.id, field_value: rawValue });\n }\n}\n\n// Campos estandar: allowlist segura (incluye source, type, dnd, dateOfBirth, companyName).\n// Excluidos a proposito: assignedTo (userIds por location -> 400), additionalEmails/Phones (objetos),\n// id/locationId-origen/dateAdded/dateUpdated/attributionSource (read-only o meta).\nvar STANDARD = ['firstName','lastName','email','phone','address1','city','state','country','postalCode','dateOfBirth','companyName','website','timezone','source','type','dnd'];\nvar body = { locationId: locationId, customFields: customFields };\nfor (var k = 0; k < STANDARD.length; k++) {\n var f = STANDARD[k];\n var val = origenData[f];\n if (val !== undefined && val !== null && val !== '') body[f] = val;\n}\nvar nombre = origenData.fullName || ((origenData.firstName || '') + ' ' + (origenData.lastName || '')).trim();\nif (nombre) body.name = nombre;\nbody.tags = (origenData.tags && origenData.tags.length > 0) ? origenData.tags : [];\n\nreturn [{ json: { body: JSON.stringify(body) } }];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3472, 848 ], "id": "ec17d3ce-b359-4b53-b87f-fed58b976c3b", "name": "Obtener el body para crear Contacto - MARCA" }, { "parameters": { "assignments": { "assignments": [ { "id": "55ff7d12-17b9-4bec-a324-e633020b131d", "name": "Name Location", "value": "={{ $json['SC BUCEFALO'] }}", "type": "string" }, { "id": "88d3daaf-ad75-4c43-9ee8-d02dbacc0607", "name": "ID LOCATION BUCEFALO", "value": "={{ $json['ID LOCATION BUCEFALO'] }}", "type": "string" }, { "id": "7698f395-5db8-415b-919e-3ad61c6566f8", "name": "Token/API", "value": "={{ $json['SC TOKEN BUCEFALO'] }}", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 1200, 608 ], "id": "401cabca-e008-49fc-914c-48ac3f378de5", "name": "Datos API Cuenta objetivo - SUCURSAL", "notes": "Esta en modo prueba forzada para Queretaro" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "91e3e213-9797-4be0-85d5-480bd1a9510c", "leftValue": "={{ $json.contacts[1] }}", "rightValue": "", "operator": { "type": "object", "operation": "exists", "singleValue": true } }, { "id": "01b8ad0c-ac85-470e-a82d-205b5688e5a5", "leftValue": "={{ $json.total }}", "rightValue": 0, "operator": { "type": "number", "operation": "equals" } } ], "combinator": "or" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ 2000, 432 ], "id": "6741aed4-8427-4614-aef2-a8242ea6793e", "name": "Si hay más de un resultado1" }, { "parameters": { "errorMessage": "El contacto no cumple los requerimientos para completar el proceso" }, "type": "n8n-nodes-base.stopAndError", "typeVersion": 1, "position": [ -976, 720 ], "id": "c9b1c7fc-8ca8-42a5-a902-812051ea6d5b", "name": "Stop and Error" }, { "parameters": { "fromEmail": "Bucefalo CRM no-reply@bucefalomarketing.com", "toEmail": "=erandi.barragan@ezcorp.com, {{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO TIENDA'] }}, {{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO DM'] }}, {{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO RDO'] }}", "subject": "=Nuevo Prospecto en {{ $('Webhook').item.json.body.Sucursal }}", "html": "=\n\n \n \n \n \n \n \n \n
\n\n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n
 
\n

\n Nuevo Prospecto Registrado
en Monte Providencia\n

\n
\n
\n
\n\n

Se ha registrado un nuevo prospecto.

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Nombre Completo{{ $('Webhook').item.json.body.full_name }}
Teléfono{{ $('Webhook').item.json.body.phone }}
Correo{{ $('Webhook').item.json.body.email }}
Sucursal{{ $('Webhook').item.json.body.Sucursal }}
Marca del Vehículo{{ $('Webhook').item.json.body['Marca del Vehiculo'] }}
Año del Vehículo{{ $('Webhook').item.json.body['Año del Vehículo'] }}
Versión del Vehículo{{ $('Webhook').item.json.body['Version del Vehiculo'] }}
Modalidad preferida{{ $('Webhook').item.json.body['¿Qué modalidad prefieres?'] }}
\n\n
\n
\n\n \n \n \n \n \n \n \n \n \n \n \n
Correo Tienda{{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO TIENDA'] }}
Correo DM{{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO DM'] }}
\n
\n \n \n \n \n \n \n
\n \n Ver Prospecto en Bucéfalo →\n \n
\n
 
\n \n\n
\n \n\n", "options": { "appendAttribution": false } }, "type": "n8n-nodes-base.emailSend", "typeVersion": 2.1, "position": [ 4016, 848 ], "id": "fb41aad8-f87d-4e5d-ac52-606fb0d1a37e", "name": "Envio a tienda", "webhookId": "97ab67d0-c4ee-48ca-a9b4-339e271a5f1c", "credentials": { "smtp": { "id": "ZtAgwqGLQDWiJ34r", "name": "SMTP account" } } }, { "parameters": { "fromEmail": "Bucefalo CRM no-reply@bucefalomarketing.com", "toEmail": "=erandi.barragan@ezcorp.com, {{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO TIENDA'] }}, {{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO DM'] }}, {{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO RDO'] }}", "subject": "=Nuevo Prospecto en {{ $('Webhook').item.json.body.Sucursal }}", "html": "=\n
\n
\n \n \n \n \n \n \n
\n
\n
\n \n \n \n \n \n \n
\n
\n \n \n \n \n \n\n \n \n \n\n \n \n \n \n
\n \n \n \n \n \n \n
\n
\n
\n
\n

\n Nuevo Prospecto Registrado en Monte Providencia\n

\n
\n
\n
\n

Se ha registrado un nuevo prospecto

\n

Nombre Completo: {{ $('Webhook').item.json.body.full_name }}

\n

Teléfono: {{ $('Webhook').item.json.body.phone }}

\n

Correo: {{ $('Webhook').item.json.body.email }}

\n

Sucursal: {{ $('Webhook').item.json.body.Sucursal }}

\n

\n Marca del Vehículo: {{ $('Webhook').item.json.body['Marca del Vehiculo'] }}

\n Año del Vehículo: {{ $('Webhook').item.json.body['Año del Vehículo'] }}\n

\n

Versión del Vehiculo: {{ $('Webhook').item.json.body['Version del Vehiculo'] }}

\n\n\n

¿Qué modalidad prefieres?: {{ $('Webhook').item.json.body['¿Qué modalidad prefieres?'] }}

\n

\n \n

Correo Tienda: {{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO TIENDA'] }}

\n

Correo DM: {{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO DM'] }}

\n
\n
\n
\n
\n
\n
\n
\n
\n\n
\n \n \n \n \n \n \n
\n
\n \n \n \n \n \n \n
\n
\n \n \n \n \n \n \n
\n \n \n \n \n \n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n\n\nLink", "options": { "appendAttribution": false } }, "type": "n8n-nodes-base.emailSend", "typeVersion": 2.1, "position": [ 4176, 1312 ], "id": "af8a81e1-d0b0-460b-9bcf-226f8c91143e", "name": "Envio a tienda1", "webhookId": "97ab67d0-c4ee-48ca-a9b4-339e271a5f1c", "credentials": { "smtp": { "id": "ZtAgwqGLQDWiJ34r", "name": "SMTP account" } } }, { "parameters": { "jsCode": "var c = $('Obtener Contacto Cuenta Origen - SUCURSAL').first().json.contact || {};\nvar cfs = c.customFields || [];\nvar v = null;\nfor (var i = 0; i < cfs.length; i++) {\n if (cfs[i].id === 'E6lI9ykWhqpj7Pmi7Qd3') { v = cfs[i].value; break; }\n}\nreturn [{ json: { cfValue: v || null } }];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1376, 416 ], "id": "5b7f8502-8fab-4984-82f2-5c21f8d4cd0f", "name": "Extraer id_contacto_sucursal de Marca", "notes": "FASE 2. Extrae el valor del CF id_contacto_sucursal del contacto Marca origen." }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 3 }, "conditions": [ { "id": "0bbcee99-2ea0-4fc7-928f-695af3ebfd3f", "leftValue": "={{ $json.cfValue }}", "rightValue": "", "operator": { "type": "string", "operation": "notEmpty", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1568, 416 ], "id": "130e9708-e5bc-4320-82ca-f210db411b20", "name": "¿cfValue presente?", "notes": "true→HTTP GET, false→cascada email" }, { "parameters": { "method": "GET", "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Extraer id_contacto_sucursal de Marca').item.json.cfValue }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Version", "value": "2021-07-28" }, { "name": "Authorization", "value": "=Bearer {{ $('Datos API Cuenta objetivo - SUCURSAL').item.json['Token/API'] }}" } ] }, "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1760, 416 ], "id": "39544f12-7c4d-48ab-8699-5faafcc9ff60", "name": "Match directo por id_contacto_sucursal", "onError": "continueRegularOutput", "alwaysOutputData": true, "notes": "GET directo a sucursal por id (el valor del CF). Si 404, IF siguiente cae a cascada." }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 3 }, "conditions": [ { "id": "840c316e-79e9-4a7d-9c32-d3e7801301e1", "leftValue": "={{ $json.contact && $json.contact.id ? 'ok' : '' }}", "rightValue": "", "operator": { "type": "string", "operation": "notEmpty", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1952, 416 ], "id": "b53f7945-64ea-4a8b-83ec-9818af443128", "name": "¿GET de contacto sucursal OK?", "notes": "true→UPDATE (Conseguir Custom Cuenta objetivo - SUCURSAL), false→cascada email" } ], "connections": { "Webhook": { "main": [ [ { "node": "Datos de Lead2", "type": "main", "index": 0 } ] ] }, "Si hay más de un resultado": { "main": [ [ { "node": "Retry - Buscar Contacto Objetivo - SUCURSAL (teléfono)", "type": "main", "index": 0 } ], [ { "node": "Obtener Contacto Cuenta objetivo - SUCURSAL", "type": "main", "index": 0 } ] ] }, "Obtener Info de cuenta origen - MARCA": { "main": [ [ { "node": "Datos API Cuenta Origen", "type": "main", "index": 0 } ] ] }, "Obtener Info de cuenta objetivo - SUCURSAL": { "main": [ [ { "node": "Datos API Cuenta objetivo - SUCURSAL", "type": "main", "index": 0 } ] ] }, "Buscar Contacto Objetivo - SUCURSAL(mail)": { "main": [ [ { "node": "Si hay más de un resultado", "type": "main", "index": 0 } ] ] }, "Retry - Buscar Contacto Objetivo - SUCURSAL (teléfono)": { "main": [ [ { "node": "Si hay más de un resultado1", "type": "main", "index": 0 } ] ] }, "Retry - Buscar Contacto Objetivo - SUCURSAL (nombre)": { "main": [ [ { "node": "Obtener Contacto Cuenta objetivo - SUCURSAL", "type": "main", "index": 0 } ] ] }, "Conseguir Custom Cuenta objetivo - SUCURSAL": { "main": [ [ { "node": "Obtener datos completos de Contacto objetivo - SUCURSAL", "type": "main", "index": 0 } ] ] }, "Obtener datos completos de Contacto objetivo - SUCURSAL": { "main": [ [ { "node": "Obtener Body para Actualizar Contacto Objetivo - SUCURSAL", "type": "main", "index": 0 } ] ] }, "Obtener Body para Actualizar Contacto Objetivo - SUCURSAL": { "main": [ [ { "node": "Actualizar Contacto Cuenta Objetivo - SUCURSAL", "type": "main", "index": 0 } ] ] }, "Conseguir Custom Cuenta Origen- SUCURSAL": { "main": [ [ { "node": "Obtener datos completos de Contacto origen - SUCURSAL", "type": "main", "index": 0 } ] ] }, "Obtener Contacto Cuenta Origen - SUCURSAL": { "main": [ [ { "node": "Conseguir Custom Cuenta Origen- SUCURSAL", "type": "main", "index": 0 } ] ] }, "Obtener datos completos de Contacto origen - SUCURSAL": { "main": [ [ { "node": "DATOS CUENTA A CHECAR", "type": "main", "index": 0 } ] ] }, "Conseguir Custom Cuenta objetivo - MARCA1": { "main": [ [ { "node": "Obtener el body para crear Contacto - MARCA", "type": "main", "index": 0 } ] ] }, "Verificar Existencia de Contcato": { "main": [ [ { "node": "Conseguir Custom Cuenta objetivo - SUCURSAL", "type": "main", "index": 0 } ], [ { "node": "Conseguir Custom Cuenta objetivo - MARCA1", "type": "main", "index": 0 } ] ] }, "Obtener Contacto Cuenta objetivo - SUCURSAL": { "main": [ [ { "node": "Verificar Existencia de Contcato", "type": "main", "index": 0 } ] ] }, "Datos API Cuenta Origen": { "main": [ [ { "node": "Obtener Contacto Cuenta Origen - SUCURSAL", "type": "main", "index": 0 } ] ] }, "DATOS CUENTA A CHECAR": { "main": [ [ { "node": "Obtener Info de cuenta objetivo - SUCURSAL", "type": "main", "index": 0 } ] ] }, "Omitir @ezcorp.com2": { "main": [ [ { "node": "Obtener Info de cuenta origen - MARCA", "type": "main", "index": 0 } ], [ { "node": "Stop and Error", "type": "main", "index": 0 } ] ] }, "Datos de Lead2": { "main": [ [ { "node": "Omitir @ezcorp.com2", "type": "main", "index": 0 } ] ] }, "Obtener el body para crear Contacto - MARCA": { "main": [ [ { "node": "Crear Contacto - Cuenta Objetivo - MARCA", "type": "main", "index": 0 } ] ] }, "Datos API Cuenta objetivo - SUCURSAL": { "main": [ [ { "node": "Extraer id_contacto_sucursal de Marca", "type": "main", "index": 0 } ] ] }, "Si hay más de un resultado1": { "main": [ [ { "node": "Retry - Buscar Contacto Objetivo - SUCURSAL (nombre)", "type": "main", "index": 0 } ], [ { "node": "Obtener Contacto Cuenta objetivo - SUCURSAL", "type": "main", "index": 0 } ] ] }, "Crear Contacto - Cuenta Objetivo - MARCA": { "main": [ [ { "node": "Envio a tienda", "type": "main", "index": 0 } ] ] }, "Extraer id_contacto_sucursal de Marca": { "main": [ [ { "node": "¿cfValue presente?", "type": "main", "index": 0 } ] ] }, "¿cfValue presente?": { "main": [ [ { "node": "Match directo por id_contacto_sucursal", "type": "main", "index": 0 } ], [ { "node": "Buscar Contacto Objetivo - SUCURSAL(mail)", "type": "main", "index": 0 } ] ] }, "Match directo por id_contacto_sucursal": { "main": [ [ { "node": "¿GET de contacto sucursal OK?", "type": "main", "index": 0 } ] ] }, "¿GET de contacto sucursal OK?": { "main": [ [ { "node": "Conseguir Custom Cuenta objetivo - SUCURSAL", "type": "main", "index": 0 } ], [ { "node": "Buscar Contacto Objetivo - SUCURSAL(mail)", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1", "errorWorkflow": "hTdgD24LIOrFWceX" } }