From 9fdd15e29267ae405fe5e4aba763df4395b4869f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Thu, 9 Apr 2026 11:33:25 -0300 Subject: [PATCH] fix: actually send the N8N_AUTH_TOKEN header to n8n --- src/services/n8n.service.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/services/n8n.service.ts b/src/services/n8n.service.ts index 53b52dc..b8c50f8 100644 --- a/src/services/n8n.service.ts +++ b/src/services/n8n.service.ts @@ -2,6 +2,7 @@ import axios from 'axios'; export const sendToN8n = async (data: any): Promise => { const n8nWebhookUrl = process.env.N8N_WEBHOOK_URL; + const n8nAuthToken = process.env.N8N_AUTH_TOKEN; if (!n8nWebhookUrl) { console.error('N8N_WEBHOOK_URL is not defined in environment variables.'); @@ -10,11 +11,17 @@ export const sendToN8n = async (data: any): Promise => { try { console.log(`Forwarding payload to n8n at ${n8nWebhookUrl}...`); - const response = await axios.post(n8nWebhookUrl, data, { - headers: { - 'Content-Type': 'application/json' - } - }); + + const headers: Record = { + 'Content-Type': 'application/json' + }; + + if (n8nAuthToken) { + // Send exactly what the user typed in the environment variable + headers['Authorization'] = n8nAuthToken; + } + + const response = await axios.post(n8nWebhookUrl, data, { headers }); console.log(`Successfully forwarded to n8n. Status: ${response.status}`); } catch (error: any) { console.error('Failed to forward payload to n8n.', error.message);