This commit is contained in:
25
src/services/n8n.service.ts
Normal file
25
src/services/n8n.service.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export const sendToN8n = async (data: any): Promise<void> => {
|
||||
const n8nWebhookUrl = process.env.N8N_WEBHOOK_URL;
|
||||
|
||||
if (!n8nWebhookUrl) {
|
||||
console.error('N8N_WEBHOOK_URL is not defined in environment variables.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`Forwarding payload to n8n at ${n8nWebhookUrl}...`);
|
||||
const response = await axios.post(n8nWebhookUrl, data, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
console.log(`Successfully forwarded to n8n. Status: ${response.status}`);
|
||||
} catch (error: any) {
|
||||
console.error('Failed to forward payload to n8n.', error.message);
|
||||
if (error.response) {
|
||||
console.error('n8n Response:', error.response.status, error.response.data);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user