Files
MP-Manager/n8n/dryrun_4UMRwxJdHFfOGHBp_20260528_010212.json
2026-05-30 14:31:19 -06:00

1705 lines
69 KiB
JSON

{
"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 - MARCA').first().json.contact; // campos estandar (crudo)\nvar origenData = $('Obtener datos completos de Contacto origen - MARCA').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 - MARCA"
},
{
"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 - MARCA"
},
{
"parameters": {
"jsCode": "// Inputs\nconst contactData = $('Obtener Contacto Cuenta Origen - MARCA').first().json.contact;\nconst allCustomFieldItems = $('Conseguir Custom Cuenta Origen - MARCA').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 - MARCA"
},
{
"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 - SUCURSAL (CREATE)"
},
{
"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 - SUCURSAL"
},
{
"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 - MARCA').first().json.contact;\nvar marcaCustomDefs = $('Conseguir Custom Cuenta objetivo - SUCURSAL (CREATE)').first().json.customFields;\nvar origenDefs = $('Conseguir Custom Cuenta Origen - MARCA').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 - SUCURSAL"
},
{
"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": "=<body style=\"word-spacing: normal; margin: 0; padding: 0; background-color: #EAF0F6;\">\n\n <!-- WRAPPER EXTERIOR -->\n <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\"\n style=\"width: 100%; background-color: #EAF0F6;\">\n <tbody>\n <tr>\n <td align=\"center\" style=\"padding: 24px 16px;\">\n\n <!-- CONTENEDOR PRINCIPAL (max 600px, responsivo) -->\n <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\"\n style=\"width: 100%; max-width: 600px; background-color: #FFFFFF; border-radius: 6px; overflow: hidden; border-collapse: collapse;\">\n <tbody>\n\n <!-- FRANJA SUPERIOR -->\n <tr>\n <td style=\"background-color: #000000; height: 8px; font-size: 0; line-height: 0;\">&nbsp;</td>\n </tr>\n\n <!-- TÍTULO -->\n <tr>\n <td align=\"center\" style=\"padding: 28px 24px 12px; font-family: arial, helvetica, sans-serif;\">\n <h2 style=\"margin: 0; font-size: 22px; line-height: 1.3; color: #000000; text-align: center;\">\n Nuevo Prospecto Registrado<br>en Monte Providencia\n </h2>\n </td>\n </tr>\n\n <!-- DIVISOR -->\n <tr>\n <td style=\"padding: 0 24px;\">\n <hr style=\"border: none; border-top: 1px solid #E0E0E0; margin: 8px 0;\">\n </td>\n </tr>\n\n <!-- DATOS DEL PROSPECTO -->\n <tr>\n <td style=\"padding: 16px 24px; font-family: arial, helvetica, sans-serif; font-size: 14px; line-height: 1.6; color: #000000;\">\n\n <p style=\"margin: 0 0 12px; text-align: center;\">Se ha registrado un <strong>nuevo prospecto</strong>.</p>\n\n <!-- TABLA DE DATOS (2 columnas: etiqueta + valor) -->\n <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width: 100%; border-collapse: collapse;\">\n <tbody>\n <tr style=\"border-bottom: 1px solid #F0F0F0;\">\n <td style=\"padding: 8px 0; width: 45%; color: #555555; vertical-align: top;\">Nombre Completo</td>\n <td style=\"padding: 8px 0; font-weight: bold; vertical-align: top;\">{{ $('Webhook').item.json.body.full_name }}</td>\n </tr>\n <tr style=\"border-bottom: 1px solid #F0F0F0;\">\n <td style=\"padding: 8px 0; color: #555555; vertical-align: top;\">Teléfono</td>\n <td style=\"padding: 8px 0; font-weight: bold; vertical-align: top;\">{{ $('Webhook').item.json.body.phone }}</td>\n </tr>\n <tr style=\"border-bottom: 1px solid #F0F0F0;\">\n <td style=\"padding: 8px 0; color: #555555; vertical-align: top;\">Correo</td>\n <td style=\"padding: 8px 0; font-weight: bold; vertical-align: top;\">{{ $('Webhook').item.json.body.email }}</td>\n </tr>\n <tr style=\"border-bottom: 1px solid #F0F0F0;\">\n <td style=\"padding: 8px 0; color: #555555; vertical-align: top;\">Sucursal</td>\n <td style=\"padding: 8px 0; font-weight: bold; vertical-align: top;\">{{ $('Webhook').item.json.body.Sucursal }}</td>\n </tr>\n <tr style=\"border-bottom: 1px solid #F0F0F0;\">\n <td style=\"padding: 8px 0; color: #555555; vertical-align: top;\">Marca del Vehículo</td>\n <td style=\"padding: 8px 0; font-weight: bold; vertical-align: top;\">{{ $('Webhook').item.json.body['Marca del Vehiculo'] }}</td>\n </tr>\n <tr style=\"border-bottom: 1px solid #F0F0F0;\">\n <td style=\"padding: 8px 0; color: #555555; vertical-align: top;\">Año del Vehículo</td>\n <td style=\"padding: 8px 0; font-weight: bold; vertical-align: top;\">{{ $('Webhook').item.json.body['Año del Vehículo'] }}</td>\n </tr>\n <tr style=\"border-bottom: 1px solid #F0F0F0;\">\n <td style=\"padding: 8px 0; color: #555555; vertical-align: top;\">Versión del Vehículo</td>\n <td style=\"padding: 8px 0; font-weight: bold; vertical-align: top;\">{{ $('Webhook').item.json.body['Version del Vehiculo'] }}</td>\n </tr>\n <tr>\n <td style=\"padding: 8px 0; color: #555555; vertical-align: top;\">Modalidad preferida</td>\n <td style=\"padding: 8px 0; font-weight: bold; vertical-align: top;\">{{ $('Webhook').item.json.body['¿Qué modalidad prefieres?'] }}</td>\n </tr>\n </tbody>\n </table>\n\n </td>\n </tr>\n\n <!-- DIVISOR + DATOS INTERNOS -->\n <tr>\n <td style=\"padding: 0 24px 16px;\">\n <hr style=\"border: none; border-top: 1px solid #E0E0E0; margin: 0 0 16px;\">\n\n <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width: 100%; border-collapse: collapse;\">\n <tbody>\n <tr style=\"border-bottom: 1px solid #F0F0F0;\">\n <td style=\"padding: 8px 0; width: 45%; color: #555555; font-family: arial, helvetica, sans-serif; font-size: 14px; vertical-align: top;\">Correo Tienda</td>\n <td style=\"padding: 8px 0; font-family: arial, helvetica, sans-serif; font-size: 14px; font-weight: bold; vertical-align: top;\">{{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO TIENDA'] }}</td>\n </tr>\n <tr>\n <td style=\"padding: 8px 0; color: #555555; font-family: arial, helvetica, sans-serif; font-size: 14px; vertical-align: top;\">Correo DM</td>\n <td style=\"padding: 8px 0; font-family: arial, helvetica, sans-serif; font-size: 14px; font-weight: bold; vertical-align: top;\">{{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO DM'] }}</td>\n </tr>\n </tbody>\n </table>\n </td>\n </tr>\n\n <!-- BOTÓN CTA -->\n <tr>\n <td align=\"center\" style=\"padding: 8px 24px 32px;\">\n <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\">\n <tbody>\n <tr>\n <td align=\"center\" style=\"background-color: #000000; border-radius: 4px;\">\n <a href=\"https://crm.bucefalocrm.io/v2/location/{{ $json.contact.locationId }}/opportunities\"\n style=\"display: inline-block; padding: 12px 28px; font-family: arial, helvetica, sans-serif; font-size: 14px; font-weight: bold; color: #FFFFFF; text-decoration: none; border-radius: 4px;\">\n Ver Prospecto en Bucéfalo →\n </a>\n </td>\n </tr>\n </tbody>\n </table>\n </td>\n </tr>\n\n <!-- FRANJA INFERIOR -->\n <tr>\n <td style=\"background-color: #000000; height: 8px; font-size: 0; line-height: 0;\">&nbsp;</td>\n </tr>\n\n </tbody>\n </table>\n <!-- FIN CONTENEDOR PRINCIPAL -->\n\n </td>\n </tr>\n </tbody>\n </table>\n <!-- FIN WRAPPER -->\n\n</body>",
"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": "=<body style=\"word-spacing:normal;\">\n <div class=\"email-content\" style=\"background-color:#EAF0F6;background-image:url('');background-repeat:no-repeat;background-size:cover;background-position:center center;\">\n <div style=\"overflow:hidden;\">\n <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"background:#FFFFFF;background-color:#FFFFFF;padding:20px 0;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;margin:0px auto;width:100%;border-color:transparent;border-collapse:inherit;\">\n <tbody>\n <tr>\n <td>\n <div>\n <div style=\"margin:0px auto;border-color:transparent;max-width:600px;\">\n <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width:100%;\">\n <tbody>\n <tr>\n <td style=\"padding:0;border-color:transparent;direction:ltr;font-size:0px;text-align:center;\">\n <div class=\"mj-column-per-100 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;\">\n <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"vertical-align:top;\" width=\"100%\">\n <tbody>\n <tr>\n <td align=\"full\" style=\"background:#000000;font-size:0px;padding:10px 25px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;word-break:break-word;\">\n <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"min-width:100%;max-width:100%;width:100%;border-collapse:collapse;border-spacing:0px;\">\n <tbody>\n <tr>\n <td>\n </td>\n </tr>\n </tbody>\n </table>\n </td>\n </tr>\n\n <tr>\n <td align=\"left\" style=\"font-size:0px;padding:10px 25px;padding-top:12px;padding-right:24px;padding-bottom:12px;padding-left:24px;word-break:break-word;\">\n <div style=\"font-family:arial, helvetica, sans-serif;font-size:14px;line-height:1.25;text-align:left;color:#000000;\">\n <h2 style=\"line-height: 1; text-align: center;\">\n <span style=\"font-size: 24px;\"><strong>Nuevo Prospecto Registrado en Monte Providencia</strong></span>\n </h2>\n </div>\n </td>\n </tr>\n\n <tr>\n <td align=\"left\" style=\"font-size:0px;padding:10px 25px;padding-top:12px;padding-right:24px;padding-bottom:12px;padding-left:24px;word-break:break-word;\">\n <div style=\"font-family:arial, helvetica, sans-serif;font-size:14px;line-height:1.25;text-align:left;color:#000000;\">\n <p>Se ha registrado un <strong>nuevo prospecto</strong></p>\n <p>Nombre Completo: <strong>{{ $('Webhook').item.json.body.full_name }}</strong></p>\n <p>Teléfono: <strong>{{ $('Webhook').item.json.body.phone }}</strong></p>\n <p>Correo: <strong>{{ $('Webhook').item.json.body.email }}</strong></p>\n <p>Sucursal: <strong>{{ $('Webhook').item.json.body.Sucursal }}</strong></p>\n <p>\n Marca del Vehículo: <strong>{{ $('Webhook').item.json.body['Marca del Vehiculo'] }}</strong><br> </p>\n Año del Vehículo: <strong>{{ $('Webhook').item.json.body['Año del Vehículo'] }}</strong>\n </p>\n <p>Versión del Vehiculo: <strong>{{ $('Webhook').item.json.body['Version del Vehiculo'] }}</strong></p>\n\n\n<p>¿Qué modalidad prefieres?: <strong>{{ $('Webhook').item.json.body['¿Qué modalidad prefieres?'] }}</strong></p>\n</p>\n <!-- NUEVAS VARIABLES AÑADIDAS -->\n <p>Correo Tienda: <strong>{{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO TIENDA'] }}</strong></p>\n <p>Correo DM: <strong>{{ $('Obtener Info de cuenta objetivo - SUCURSAL').item.json['CORREO DM'] }}</strong></p>\n </div>\n </td>\n </tr>\n </tbody>\n </table>\n </div>\n </td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n </td>\n </tr>\n </tbody>\n </table>\n </div>\n\n <div style=\"overflow:hidden;\">\n <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"background:#ffffff;background-color:#ffffff;padding:20px 0;margin:0px auto;width:100%;border-color:transparent;border-collapse:inherit;\">\n <tbody>\n <tr>\n <td>\n <div style=\"margin:0px auto;border-color:transparent;max-width:600px;\">\n <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width:100%;\">\n <tbody>\n <tr>\n <td style=\"padding:0;border-color:transparent;direction:ltr;font-size:0px;text-align:center;\">\n <div class=\"mj-column-per-100 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;\">\n <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\">\n <tbody>\n <tr>\n <td align=\"full\" style=\"font-size:0px;padding:10px 25px;word-break:break-word;\">\n <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"min-width:100%;max-width:100%;width:100%;border-collapse:collapse;border-spacing:0px;\">\n <tbody>\n <tr>\n <td>\n </td>\n </tr>\n </tbody>\n </table>\n </td>\n </tr>\n </tbody>\n </table>\n </div>\n </td>\n </tr>\n </tbody>\n </table>\n </div>\n </td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n</body>\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 - MARCA').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": "e2d353e2-6ecd-4f79-b2ae-3903168b5edf",
"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": "4be77ccc-c47b-451a-8740-94dd095face7",
"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": "9c6233c0-bff1-4c41-8acb-64d5f4328c35",
"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": "8e28b669-d66d-454a-9d10-ae457324ab8e",
"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": "b3306203-617e-48bb-b97a-24f909e1405b",
"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": "66a46e78-309f-47c9-96aa-0eb23b951233",
"name": "¿GET de contacto sucursal OK?",
"notes": "true→UPDATE (Conseguir Custom Cuenta objetivo - SUCURSAL), false→cascada email"
},
{
"parameters": {
"jsCode": "var defs = $('Conseguir Custom Cuenta objetivo - SUCURSAL (CREATE)').first().json.customFields || [];\nvar def = defs.find(function(d){ return d.fieldKey === 'contact.id_contacto_sucursal'; });\nvar createdContact = ($('Crear Contacto - Cuenta Objetivo - SUCURSAL').first().json || {}).contact || {};\nvar newId = createdContact.id;\nreturn [{ json: { fieldId: def ? def.id : null, newContactId: newId || null } }];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
3920,
848
],
"id": "cefa69d0-b818-4ddd-8afe-e8243947ccd0",
"name": "Resolver fieldId y newContactId post-CREATE",
"notes": "FASE 3. Extrae fieldId del CF en sucursal y el id del contacto recién creado."
},
{
"parameters": {
"method": "PUT",
"url": "=https://services.leadconnectorhq.com/contacts/{{ $json.newContactId }}",
"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'] }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"customFields\": [\n {\n \"id\": \"{{ $json.fieldId }}\",\n \"key\": \"contact.id_contacto_sucursal\",\n \"field_value\": \"{{ $json.newContactId }}\"\n }\n ]\n}",
"options": {
"redirect": {
"redirect": {}
}
}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
4112,
848
],
"id": "5f03f7a1-fbd4-4320-9655-7e06f49199e0",
"name": "Enlazar CF en SUCURSAL (autoref)",
"onError": "continueRegularOutput",
"notes": "FASE 3. PUT al contacto sucursal recién creado: CF id_contacto_sucursal = su propio id."
},
{
"parameters": {
"method": "PUT",
"url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').item.json.body.contact_id }}",
"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'] }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"customFields\": [\n {\n \"id\": \"E6lI9ykWhqpj7Pmi7Qd3\",\n \"key\": \"contact.id_contacto_sucursal\",\n \"field_value\": \"{{ $('Resolver fieldId y newContactId post-CREATE').item.json.newContactId }}\"\n }\n ]\n}",
"options": {
"redirect": {
"redirect": {}
}
}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
4304,
848
],
"id": "8110e7ae-c941-44a4-ac2a-99dc5358f4ae",
"name": "Enlazar CF en MARCA",
"onError": "continueRegularOutput",
"notes": "FASE 3. PUT al contacto Marca origen: CF id_contacto_sucursal = id del nuevo sucursal."
}
],
"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
}
]
]
},
"Verificar Existencia de Contcato": {
"main": [
[
{
"node": "Conseguir Custom Cuenta objetivo - SUCURSAL",
"type": "main",
"index": 0
}
],
[
{
"node": "Conseguir Custom Cuenta objetivo - SUCURSAL (CREATE)",
"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 - MARCA",
"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
}
]
]
},
"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
}
]
]
},
"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
}
]
]
},
"Resolver fieldId y newContactId post-CREATE": {
"main": [
[
{
"node": "Enlazar CF en SUCURSAL (autoref)",
"type": "main",
"index": 0
}
]
]
},
"Enlazar CF en SUCURSAL (autoref)": {
"main": [
[
{
"node": "Enlazar CF en MARCA",
"type": "main",
"index": 0
}
]
]
},
"Enlazar CF en MARCA": {
"main": [
[
{
"node": "Envio a tienda",
"type": "main",
"index": 0
}
]
]
},
"Crear Contacto - Cuenta Objetivo - SUCURSAL": {
"main": [
[
{
"node": "Resolver fieldId y newContactId post-CREATE",
"type": "main",
"index": 0
}
]
]
},
"Conseguir Custom Cuenta objetivo - SUCURSAL (CREATE)": {
"main": [
[
{
"node": "Obtener el body para crear Contacto - SUCURSAL",
"type": "main",
"index": 0
}
]
]
},
"Obtener Contacto Cuenta Origen - MARCA": {
"main": [
[
{
"node": "Conseguir Custom Cuenta Origen - MARCA",
"type": "main",
"index": 0
}
]
]
},
"Conseguir Custom Cuenta Origen - MARCA": {
"main": [
[
{
"node": "Obtener datos completos de Contacto origen - MARCA",
"type": "main",
"index": 0
}
]
]
},
"Obtener datos completos de Contacto origen - MARCA": {
"main": [
[
{
"node": "DATOS CUENTA A CHECAR",
"type": "main",
"index": 0
}
]
]
},
"Obtener el body para crear Contacto - SUCURSAL": {
"main": [
[
{
"node": "Crear Contacto - Cuenta Objetivo - SUCURSAL",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1",
"errorWorkflow": "hTdgD24LIOrFWceX"
}
}