{ "updatedAt": "2026-06-16T13:12:18.167Z", "createdAt": "2026-06-16T12:18:54.043Z", "id": "k2NNakqj2TaP0HKy", "name": "Tablero CDC - Sync Proyecto a Banco Fulgencio", "description": null, "active": true, "isArchived": false, "nodes": [ { "parameters": { "httpMethod": "POST", "path": "tablero-cdc-sync-fulgencio", "responseMode": "responseNode", "options": {} }, "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ 0, 0 ], "id": "5fbd25cf-6c2d-4364-a10e-91954b61256f", "name": "Webhook", "webhookId": "b9c9551b-86ee-4f3d-bbe2-12e93eef4b35" }, { "parameters": { "jsCode": "const input = $json || {};\nconst body = input.body || input;\n\nconst projectId =\n body.project_id ||\n body.projectId ||\n body.id ||\n '';\n\nconst action =\n String(body.action || 'sync').trim().toLowerCase();\n\nif (!projectId) {\n throw new Error('Falta project_id en el payload del webhook');\n}\n\nreturn [\n {\n json: {\n action,\n project_id: projectId,\n received_at: new Date().toISOString(),\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 208, 0 ], "id": "61c5d83f-33d1-45d8-bb6a-4f657461f3c1", "name": "Code - Preparar project_id" }, { "parameters": { "url": "=https://dbit.digitalcompass.agency/rest/v1/tablero_cdc_projects?id=eq.{{ $('Code - Preparar project_id').first().json.project_id }}&select=*", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "apikey", "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q" }, { "name": "Authorization", "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q" }, { "name": "Accept", "value": " application/json" }, { "name": "Content-Type", "value": "application/json" } ] }, "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 416, 0 ], "id": "007cdb0b-ab8e-4558-8ce0-b4cf238b2ef9", "name": "Supabase - Leer proyecto" }, { "parameters": { "url": "=https://dbit.digitalcompass.agency/rest/v1/tablero_cdc_project_links?project_id=eq.{{ $('Code - Preparar project_id').first().json.project_id }}&select=*&order=created_at.asc", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "apikey", "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q" }, { "name": "Authorization", "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q" }, { "name": "Accept", "value": " application/json" }, { "name": "Content-Type", "value": "application/json" } ] }, "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 592, 0 ], "id": "ab47b077-7d17-4145-9a19-c0b9134a7931", "name": "Supabase - Leer links del proyecto", "alwaysOutputData": true }, { "parameters": { "jsCode": "function getNodeJson(nodeName) {\n try {\n return $(nodeName).first().json;\n } catch (error) {\n return {};\n }\n}\n\nfunction getNodeItems(nodeName) {\n try {\n return $(nodeName).all();\n } catch (error) {\n return [];\n }\n}\n\nfunction normalizeProjectResponse(value) {\n if (Array.isArray(value)) return value[0] || null;\n return value || null;\n}\n\nfunction normalizeLinksResponse(items) {\n const links = [];\n\n for (const item of items) {\n const json = item.json;\n\n if (Array.isArray(json)) {\n links.push(...json);\n } else if (json && typeof json === 'object') {\n links.push(json);\n }\n }\n\n return links.filter(link => link && link.url);\n}\n\nfunction clean(value) {\n return String(value ?? '').trim();\n}\n\nfunction getYear(value) {\n const date = value ? new Date(value) : new Date();\n\n if (Number.isNaN(date.getTime())) {\n return String(new Date().getFullYear());\n }\n\n return String(date.getFullYear());\n}\n\nfunction extractGoogleFileId(url) {\n const text = clean(url);\n\n if (!text) return '';\n\n const patterns = [\n /\\/d\\/([a-zA-Z0-9_-]+)/,\n /id=([a-zA-Z0-9_-]+)/,\n /\\/file\\/d\\/([a-zA-Z0-9_-]+)/,\n /\\/presentation\\/d\\/([a-zA-Z0-9_-]+)/,\n ];\n\n for (const pattern of patterns) {\n const match = text.match(pattern);\n if (match && match[1]) return match[1];\n }\n\n return '';\n}\n\nconst rawProject = getNodeJson('Supabase - Leer proyecto');\nconst project = normalizeProjectResponse(rawProject);\n\nif (!project || !project.id) {\n throw new Error('No se encontró el proyecto en Supabase. Revisa el project_id.');\n}\n\nconst linkItems = getNodeItems('Supabase - Leer links del proyecto');\nconst links = normalizeLinksResponse(linkItems);\n\nconst proposalLinks = links.filter(link =>\n String(link.link_type || '').toLowerCase() === 'proposal'\n);\n\nif (!proposalLinks.length) {\n return [\n {\n json: {\n ok: true,\n skipped: true,\n reason: 'El proyecto no tiene links de propuesta. No se escribe en Banco Fulgencio.',\n project_id: project.id,\n },\n },\n ];\n}\n\nreturn proposalLinks.map((link, index) => {\n const proposalUrl = clean(link.url);\n const fileId = extractGoogleFileId(proposalUrl);\n const syncKey = `${project.id}::${fileId || proposalUrl}`;\n\n return {\n json: {\n skipped: false,\n\n 'NOMBRE': project.title || '',\n 'TIPO DE ACCION': 'PENDIENTE CLASIFICAR',\n 'CLIENTE': project.client || '',\n 'MARCA': project.brand || '',\n 'PAIS': project.country || '',\n 'CANAL': '',\n 'AMBIENTE DE COMPRA (RE)': '',\n 'TÁCTICA PROMOCIONAL': '',\n 'APROBADA': '',\n 'ETIQUETAS': '',\n 'AÑO': getYear(project.created_at),\n 'Enlace a la propuesta': proposalUrl,\n 'Descripcion': project.description || project.title || '',\n 'file_id': fileId,\n 'nombre_archivo': '',\n 'mime_type': '',\n 'fuente_pais': 'Tablero CDC',\n 'confianza_pais': '',\n 'requiere_revision': '',\n 'procesado_ia': 'NO',\n 'ultima_actualizacion': new Date().toISOString(),\n 'motivos_revision': '',\n 'Enlaces a propuestas ejecutadas': '',\n\n 'tablero_sync_key': syncKey,\n 'tablero_project_id': project.id,\n 'tablero_origen': 'Tablero CDC',\n },\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 800, 0 ], "id": "4a37a2a6-3138-455b-8806-288d852873a6", "name": "Code - Preparar filas Fulgencio" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "8b0c7244-a4a1-4fd9-b2eb-dc62b98fb7a3", "leftValue": "={{ $json.skipped }}", "rightValue": "", "operator": { "type": "boolean", "operation": "false", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ 1008, 0 ], "id": "5b14f1ea-8203-4daf-8f14-b39da2a7dc97", "name": "IF - Tiene filas para escribir?" }, { "parameters": { "respondWith": "json", "responseBody": "{\n \"ok\": true,\n \"message\": \"Proyecto sincronizado con Banco Fulgencio\",\n \"source\": \"Tablero CDC\"\n}", "options": {} }, "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.5, "position": [ 1520, -96 ], "id": "c221409e-9777-4453-afa1-ad8bc7107910", "name": "Respond to Webhook" }, { "parameters": { "respondWith": "json", "responseBody": "{\n \"ok\": true,\n \"skipped\": true,\n \"message\": \"Proyecto sin links de propuesta. No se escribió en Banco Fulgencio.\"\n}", "options": {} }, "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.5, "position": [ 1216, 96 ], "id": "363e5ac4-43be-4a9e-afd0-923bec81a017", "name": "Respond to Webhook1" }, { "parameters": { "operation": "appendOrUpdate", "documentId": { "__rl": true, "value": "1iy3lC3DS3ZfShb7d26iQOrPjx9s_3B-PC07XfYew7ng", "mode": "list", "cachedResultName": "BANCO DE PROPUESTAS DE CDC PARA FULGENCIO FUMADO", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1iy3lC3DS3ZfShb7d26iQOrPjx9s_3B-PC07XfYew7ng/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": "gid=0", "mode": "list", "cachedResultName": "propuestas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1iy3lC3DS3ZfShb7d26iQOrPjx9s_3B-PC07XfYew7ng/edit#gid=0" }, "columns": { "mappingMode": "defineBelow", "value": { "NOMBRE": "={{ $json[\"NOMBRE\"] }}", "TIPO DE ACCION": "={{ $json[\"TIPO DE ACCION\"] }}", "CLIENTE": "={{ $json[\"CLIENTE\"] }}", "MARCA": "={{ $json[\"MARCA\"] }}", "PAIS": "={{ $json[\"PAIS\"] }}", "CANAL": "={{ $json[\"CANAL\"] }}", "AMBIENTE DE COMPRA (RE)": "={{ $json[\"AMBIENTE DE COMPRA (RE)\"] }}", "TÁCTICA PROMOCIONAL": "={{ $json[\"TÁCTICA PROMOCIONAL\"] }}", "APROBADA": "={{ $json[\"APROBADA\"] }}", "ETIQUETAS": "={{ $json[\"ETIQUETAS\"] }}", "AÑO": "={{ $json[\"AÑO\"] }}", "Enlace a la propuesta": "={{ $json[\"Enlace a la propuesta\"] }}", "Descripcion": "={{ $json[\"Descripcion\"] }}", "file_id": "={{ $json[\"file_id\"] }}", "nombre_archivo": "={{ $json[\"nombre_archivo\"] }}", "mime_type": "={{ $json[\"mime_type\"] }}", "fuente_pais": "={{ $json[\"fuente_pais\"] }}", "confianza_pais": "={{ $json[\"confianza_pais\"] }}", "requiere_revision": "={{ $json[\"requiere_revision\"] }}", "procesado_ia": "={{ $json[\"procesado_ia\"] }}", "ultima_actualizacion": "={{ $json[\"ultima_actualizacion\"] }}", "motivos_revision": "={{ $json[\"motivos_revision\"] }}", "Enlaces a propuestas ejecutadas": "={{ $json[\"Enlaces a propuestas ejecutadas\"] }}", "tablero_project_id": "={{ $json[\"tablero_project_id\"] }}", "tablero_origen": "={{ $json[\"tablero_origen\"] }}", "tablero_sync_key": "={{ $json[\"tablero_sync_key\"] }}" }, "matchingColumns": [ "tablero_sync_key" ], "schema": [ { "id": "NOMBRE", "displayName": "NOMBRE", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "TIPO DE ACCION", "displayName": "TIPO DE ACCION", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "CLIENTE", "displayName": "CLIENTE", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "MARCA", "displayName": "MARCA", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "PAIS", "displayName": "PAIS", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "CANAL", "displayName": "CANAL", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "AMBIENTE DE COMPRA (RE)", "displayName": "AMBIENTE DE COMPRA (RE)", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "TÁCTICA PROMOCIONAL", "displayName": "TÁCTICA PROMOCIONAL", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "APROBADA", "displayName": "APROBADA", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ETIQUETAS", "displayName": "ETIQUETAS", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "AÑO", "displayName": "AÑO", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "Enlace a la propuesta", "displayName": "Enlace a la propuesta", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "Descripcion", "displayName": "Descripcion", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "file_id", "displayName": "file_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "nombre_archivo", "displayName": "nombre_archivo", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "mime_type", "displayName": "mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fuente_pais", "displayName": "fuente_pais", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "confianza_pais", "displayName": "confianza_pais", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "requiere_revision", "displayName": "requiere_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "procesado_ia", "displayName": "procesado_ia", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actualizacion", "displayName": "ultima_actualizacion", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivos_revision", "displayName": "motivos_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "Enlaces a propuestas ejecutadas", "displayName": "Enlaces a propuestas ejecutadas", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "tablero_sync_key", "displayName": "tablero_sync_key", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "tablero_project_id", "displayName": "tablero_project_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "tablero_origen", "displayName": "tablero_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 1312, -96 ], "id": "f3bee0f1-50da-4908-923f-51b17a2dbbdc", "name": "Google Sheets - Upsert Banco Fulgencio", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } } ], "connections": { "Webhook": { "main": [ [ { "node": "Code - Preparar project_id", "type": "main", "index": 0 } ] ] }, "Code - Preparar project_id": { "main": [ [ { "node": "Supabase - Leer proyecto", "type": "main", "index": 0 } ] ] }, "Supabase - Leer proyecto": { "main": [ [ { "node": "Supabase - Leer links del proyecto", "type": "main", "index": 0 } ] ] }, "Supabase - Leer links del proyecto": { "main": [ [ { "node": "Code - Preparar filas Fulgencio", "type": "main", "index": 0 } ] ] }, "Code - Preparar filas Fulgencio": { "main": [ [ { "node": "IF - Tiene filas para escribir?", "type": "main", "index": 0 } ] ] }, "IF - Tiene filas para escribir?": { "main": [ [ { "node": "Google Sheets - Upsert Banco Fulgencio", "type": "main", "index": 0 } ], [ { "node": "Respond to Webhook1", "type": "main", "index": 0 } ] ] }, "Google Sheets - Upsert Banco Fulgencio": { "main": [ [ { "node": "Respond to Webhook", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1", "binaryMode": "separate" }, "staticData": null, "meta": { "templateCredsSetupCompleted": true }, "versionId": "5d61630a-1078-4e90-b0d0-2586454f1878", "activeVersionId": "5d61630a-1078-4e90-b0d0-2586454f1878", "versionCounter": 94, "triggerCount": 1, "shared": [ { "updatedAt": "2026-06-16T12:18:54.046Z", "createdAt": "2026-06-16T12:18:54.046Z", "role": "workflow:owner", "workflowId": "k2NNakqj2TaP0HKy", "projectId": "PJpTANzTXIFibWsW", "project": { "updatedAt": "2026-04-22T14:25:09.686Z", "createdAt": "2026-04-22T14:22:54.790Z", "id": "PJpTANzTXIFibWsW", "name": "Isaac Aracena ", "type": "personal", "icon": null, "description": null, "creatorId": "0a88c0b1-928e-4412-896e-c5d1c99b2029" } } ], "tags": [], "activeVersion": { "updatedAt": "2026-06-16T13:12:19.000Z", "createdAt": "2026-06-16T12:37:18.224Z", "versionId": "5d61630a-1078-4e90-b0d0-2586454f1878", "workflowId": "k2NNakqj2TaP0HKy", "nodes": [ { "parameters": { "httpMethod": "POST", "path": "tablero-cdc-sync-fulgencio", "responseMode": "responseNode", "options": {} }, "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ 0, 0 ], "id": "5fbd25cf-6c2d-4364-a10e-91954b61256f", "name": "Webhook", "webhookId": "b9c9551b-86ee-4f3d-bbe2-12e93eef4b35" }, { "parameters": { "jsCode": "const input = $json || {};\nconst body = input.body || input;\n\nconst projectId =\n body.project_id ||\n body.projectId ||\n body.id ||\n '';\n\nconst action =\n String(body.action || 'sync').trim().toLowerCase();\n\nif (!projectId) {\n throw new Error('Falta project_id en el payload del webhook');\n}\n\nreturn [\n {\n json: {\n action,\n project_id: projectId,\n received_at: new Date().toISOString(),\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 208, 0 ], "id": "61c5d83f-33d1-45d8-bb6a-4f657461f3c1", "name": "Code - Preparar project_id" }, { "parameters": { "url": "=https://dbit.digitalcompass.agency/rest/v1/tablero_cdc_projects?id=eq.{{ $('Code - Preparar project_id').first().json.project_id }}&select=*", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "apikey", "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q" }, { "name": "Authorization", "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q" }, { "name": "Accept", "value": " application/json" }, { "name": "Content-Type", "value": "application/json" } ] }, "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 416, 0 ], "id": "007cdb0b-ab8e-4558-8ce0-b4cf238b2ef9", "name": "Supabase - Leer proyecto" }, { "parameters": { "url": "=https://dbit.digitalcompass.agency/rest/v1/tablero_cdc_project_links?project_id=eq.{{ $('Code - Preparar project_id').first().json.project_id }}&select=*&order=created_at.asc", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "apikey", "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q" }, { "name": "Authorization", "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q" }, { "name": "Accept", "value": " application/json" }, { "name": "Content-Type", "value": "application/json" } ] }, "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 592, 0 ], "id": "ab47b077-7d17-4145-9a19-c0b9134a7931", "name": "Supabase - Leer links del proyecto", "alwaysOutputData": true }, { "parameters": { "jsCode": "function getNodeJson(nodeName) {\n try {\n return $(nodeName).first().json;\n } catch (error) {\n return {};\n }\n}\n\nfunction getNodeItems(nodeName) {\n try {\n return $(nodeName).all();\n } catch (error) {\n return [];\n }\n}\n\nfunction normalizeProjectResponse(value) {\n if (Array.isArray(value)) return value[0] || null;\n return value || null;\n}\n\nfunction normalizeLinksResponse(items) {\n const links = [];\n\n for (const item of items) {\n const json = item.json;\n\n if (Array.isArray(json)) {\n links.push(...json);\n } else if (json && typeof json === 'object') {\n links.push(json);\n }\n }\n\n return links.filter(link => link && link.url);\n}\n\nfunction clean(value) {\n return String(value ?? '').trim();\n}\n\nfunction getYear(value) {\n const date = value ? new Date(value) : new Date();\n\n if (Number.isNaN(date.getTime())) {\n return String(new Date().getFullYear());\n }\n\n return String(date.getFullYear());\n}\n\nfunction extractGoogleFileId(url) {\n const text = clean(url);\n\n if (!text) return '';\n\n const patterns = [\n /\\/d\\/([a-zA-Z0-9_-]+)/,\n /id=([a-zA-Z0-9_-]+)/,\n /\\/file\\/d\\/([a-zA-Z0-9_-]+)/,\n /\\/presentation\\/d\\/([a-zA-Z0-9_-]+)/,\n ];\n\n for (const pattern of patterns) {\n const match = text.match(pattern);\n if (match && match[1]) return match[1];\n }\n\n return '';\n}\n\nconst rawProject = getNodeJson('Supabase - Leer proyecto');\nconst project = normalizeProjectResponse(rawProject);\n\nif (!project || !project.id) {\n throw new Error('No se encontró el proyecto en Supabase. Revisa el project_id.');\n}\n\nconst linkItems = getNodeItems('Supabase - Leer links del proyecto');\nconst links = normalizeLinksResponse(linkItems);\n\nconst proposalLinks = links.filter(link =>\n String(link.link_type || '').toLowerCase() === 'proposal'\n);\n\nif (!proposalLinks.length) {\n return [\n {\n json: {\n ok: true,\n skipped: true,\n reason: 'El proyecto no tiene links de propuesta. No se escribe en Banco Fulgencio.',\n project_id: project.id,\n },\n },\n ];\n}\n\nreturn proposalLinks.map((link, index) => {\n const proposalUrl = clean(link.url);\n const fileId = extractGoogleFileId(proposalUrl);\n const syncKey = `${project.id}::${fileId || proposalUrl}`;\n\n return {\n json: {\n skipped: false,\n\n 'NOMBRE': project.title || '',\n 'TIPO DE ACCION': 'PENDIENTE CLASIFICAR',\n 'CLIENTE': project.client || '',\n 'MARCA': project.brand || '',\n 'PAIS': project.country || '',\n 'CANAL': '',\n 'AMBIENTE DE COMPRA (RE)': '',\n 'TÁCTICA PROMOCIONAL': '',\n 'APROBADA': '',\n 'ETIQUETAS': '',\n 'AÑO': getYear(project.created_at),\n 'Enlace a la propuesta': proposalUrl,\n 'Descripcion': project.description || project.title || '',\n 'file_id': fileId,\n 'nombre_archivo': '',\n 'mime_type': '',\n 'fuente_pais': 'Tablero CDC',\n 'confianza_pais': '',\n 'requiere_revision': '',\n 'procesado_ia': 'NO',\n 'ultima_actualizacion': new Date().toISOString(),\n 'motivos_revision': '',\n 'Enlaces a propuestas ejecutadas': '',\n\n 'tablero_sync_key': syncKey,\n 'tablero_project_id': project.id,\n 'tablero_origen': 'Tablero CDC',\n },\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 800, 0 ], "id": "4a37a2a6-3138-455b-8806-288d852873a6", "name": "Code - Preparar filas Fulgencio" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "8b0c7244-a4a1-4fd9-b2eb-dc62b98fb7a3", "leftValue": "={{ $json.skipped }}", "rightValue": "", "operator": { "type": "boolean", "operation": "false", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ 1008, 0 ], "id": "5b14f1ea-8203-4daf-8f14-b39da2a7dc97", "name": "IF - Tiene filas para escribir?" }, { "parameters": { "respondWith": "json", "responseBody": "{\n \"ok\": true,\n \"message\": \"Proyecto sincronizado con Banco Fulgencio\",\n \"source\": \"Tablero CDC\"\n}", "options": {} }, "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.5, "position": [ 1520, -96 ], "id": "c221409e-9777-4453-afa1-ad8bc7107910", "name": "Respond to Webhook" }, { "parameters": { "respondWith": "json", "responseBody": "{\n \"ok\": true,\n \"skipped\": true,\n \"message\": \"Proyecto sin links de propuesta. No se escribió en Banco Fulgencio.\"\n}", "options": {} }, "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.5, "position": [ 1216, 96 ], "id": "363e5ac4-43be-4a9e-afd0-923bec81a017", "name": "Respond to Webhook1" }, { "parameters": { "operation": "appendOrUpdate", "documentId": { "__rl": true, "value": "1iy3lC3DS3ZfShb7d26iQOrPjx9s_3B-PC07XfYew7ng", "mode": "list", "cachedResultName": "BANCO DE PROPUESTAS DE CDC PARA FULGENCIO FUMADO", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1iy3lC3DS3ZfShb7d26iQOrPjx9s_3B-PC07XfYew7ng/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": "gid=0", "mode": "list", "cachedResultName": "propuestas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1iy3lC3DS3ZfShb7d26iQOrPjx9s_3B-PC07XfYew7ng/edit#gid=0" }, "columns": { "mappingMode": "defineBelow", "value": { "NOMBRE": "={{ $json[\"NOMBRE\"] }}", "TIPO DE ACCION": "={{ $json[\"TIPO DE ACCION\"] }}", "CLIENTE": "={{ $json[\"CLIENTE\"] }}", "MARCA": "={{ $json[\"MARCA\"] }}", "PAIS": "={{ $json[\"PAIS\"] }}", "CANAL": "={{ $json[\"CANAL\"] }}", "AMBIENTE DE COMPRA (RE)": "={{ $json[\"AMBIENTE DE COMPRA (RE)\"] }}", "TÁCTICA PROMOCIONAL": "={{ $json[\"TÁCTICA PROMOCIONAL\"] }}", "APROBADA": "={{ $json[\"APROBADA\"] }}", "ETIQUETAS": "={{ $json[\"ETIQUETAS\"] }}", "AÑO": "={{ $json[\"AÑO\"] }}", "Enlace a la propuesta": "={{ $json[\"Enlace a la propuesta\"] }}", "Descripcion": "={{ $json[\"Descripcion\"] }}", "file_id": "={{ $json[\"file_id\"] }}", "nombre_archivo": "={{ $json[\"nombre_archivo\"] }}", "mime_type": "={{ $json[\"mime_type\"] }}", "fuente_pais": "={{ $json[\"fuente_pais\"] }}", "confianza_pais": "={{ $json[\"confianza_pais\"] }}", "requiere_revision": "={{ $json[\"requiere_revision\"] }}", "procesado_ia": "={{ $json[\"procesado_ia\"] }}", "ultima_actualizacion": "={{ $json[\"ultima_actualizacion\"] }}", "motivos_revision": "={{ $json[\"motivos_revision\"] }}", "Enlaces a propuestas ejecutadas": "={{ $json[\"Enlaces a propuestas ejecutadas\"] }}", "tablero_project_id": "={{ $json[\"tablero_project_id\"] }}", "tablero_origen": "={{ $json[\"tablero_origen\"] }}", "tablero_sync_key": "={{ $json[\"tablero_sync_key\"] }}" }, "matchingColumns": [ "tablero_sync_key" ], "schema": [ { "id": "NOMBRE", "displayName": "NOMBRE", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "TIPO DE ACCION", "displayName": "TIPO DE ACCION", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "CLIENTE", "displayName": "CLIENTE", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "MARCA", "displayName": "MARCA", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "PAIS", "displayName": "PAIS", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "CANAL", "displayName": "CANAL", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "AMBIENTE DE COMPRA (RE)", "displayName": "AMBIENTE DE COMPRA (RE)", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "TÁCTICA PROMOCIONAL", "displayName": "TÁCTICA PROMOCIONAL", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "APROBADA", "displayName": "APROBADA", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ETIQUETAS", "displayName": "ETIQUETAS", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "AÑO", "displayName": "AÑO", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "Enlace a la propuesta", "displayName": "Enlace a la propuesta", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "Descripcion", "displayName": "Descripcion", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "file_id", "displayName": "file_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "nombre_archivo", "displayName": "nombre_archivo", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "mime_type", "displayName": "mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fuente_pais", "displayName": "fuente_pais", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "confianza_pais", "displayName": "confianza_pais", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "requiere_revision", "displayName": "requiere_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "procesado_ia", "displayName": "procesado_ia", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actualizacion", "displayName": "ultima_actualizacion", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivos_revision", "displayName": "motivos_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "Enlaces a propuestas ejecutadas", "displayName": "Enlaces a propuestas ejecutadas", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "tablero_sync_key", "displayName": "tablero_sync_key", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "tablero_project_id", "displayName": "tablero_project_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "tablero_origen", "displayName": "tablero_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 1312, -96 ], "id": "f3bee0f1-50da-4908-923f-51b17a2dbbdc", "name": "Google Sheets - Upsert Banco Fulgencio", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } } ], "connections": { "Webhook": { "main": [ [ { "node": "Code - Preparar project_id", "type": "main", "index": 0 } ] ] }, "Code - Preparar project_id": { "main": [ [ { "node": "Supabase - Leer proyecto", "type": "main", "index": 0 } ] ] }, "Supabase - Leer proyecto": { "main": [ [ { "node": "Supabase - Leer links del proyecto", "type": "main", "index": 0 } ] ] }, "Supabase - Leer links del proyecto": { "main": [ [ { "node": "Code - Preparar filas Fulgencio", "type": "main", "index": 0 } ] ] }, "Code - Preparar filas Fulgencio": { "main": [ [ { "node": "IF - Tiene filas para escribir?", "type": "main", "index": 0 } ] ] }, "IF - Tiene filas para escribir?": { "main": [ [ { "node": "Google Sheets - Upsert Banco Fulgencio", "type": "main", "index": 0 } ], [ { "node": "Respond to Webhook1", "type": "main", "index": 0 } ] ] }, "Google Sheets - Upsert Banco Fulgencio": { "main": [ [ { "node": "Respond to Webhook", "type": "main", "index": 0 } ] ] } }, "authors": "Isaac Aracena", "name": "Version 5d61630a", "description": "", "autosaved": true, "workflowPublishHistory": [ { "createdAt": "2026-06-16T13:12:19.591Z", "id": 1416, "workflowId": "k2NNakqj2TaP0HKy", "versionId": "5d61630a-1078-4e90-b0d0-2586454f1878", "event": "activated", "userId": "0a88c0b1-928e-4412-896e-c5d1c99b2029" } ] } }