7.6 KiB
N8N Configuration Fix - Environment Variables & Webhook Activation
🔍 Problems Identified
Based on your error logs, there are THREE critical issues:
- ❌ N8N_API_KEY is not set in environment variables
- ❌ 404 Error: Webhook "mission-created" is not registered (workflow not active)
- ❌ 500 Error: "Error in workflow" (workflow is running but failing)
✅ Fix 1: Set N8N_API_KEY Environment Variable
Problem
N8N_API_KEY is not set in environment variables
Solution
Add to your .env or .env.local file:
N8N_API_KEY=LwgeE1ntADD20OuWC88S3pR0EaO7FtO4
Or if using a different key, use your actual N8N API key.
Where to Add
-
Local Development (
.env.local):N8N_API_KEY=your-actual-api-key-here -
Production (environment variables in your hosting platform):
- Vercel: Settings → Environment Variables
- Docker:
docker-compose.ymlor.envfile - CapRover: App Settings → App Configs → Environment Variables
Verify It's Set
After adding, restart your application and check logs. You should NOT see:
N8N_API_KEY is not set in environment variables
✅ Fix 2: Activate N8N Workflow
Problem
404 Error: The requested webhook "mission-created" is not registered.
Hint: Click the 'Execute workflow' button on the canvas, then try again.
Solution
In N8N Interface:
-
Open your workflow in N8N (the one with the webhook node)
-
Click "Active" toggle in the top right to activate the workflow
- The toggle should be GREEN/ON ✅
- If it's gray/off, click it to activate
-
Verify the webhook node:
- The webhook node should show as "Active"
- The webhook path should be:
mission-created - The full URL should be:
https://brain.slm-lab.net/webhook/mission-created
Alternative: Test Mode
If you're testing:
- Click "Execute Workflow" button on the canvas
- This activates the webhook for one test call
- After the test, activate the workflow permanently
Verify Webhook is Active
Test the webhook URL:
curl -X POST https://brain.slm-lab.net/webhook/mission-created \
-H "Content-Type: application/json" \
-d '{"test": "data"}'
Expected:
- If active: Should trigger the workflow (may return error if data is invalid, but should not be 404)
- If not active: Returns 404 with message about webhook not registered
✅ Fix 3: Fix Workflow Errors (500 Error)
Problem
500 Error: {"message":"Error in workflow"}
This means the workflow is running but encountering an error. Common causes:
Common Issues & Fixes
Issue 3.1: Missing missionId in Process Mission Data
Check: The "Process Mission Data" node should include missionId in its output.
Fix: Ensure the node includes:
missionId: missionData?.missionId || missionData?.body?.missionId
Issue 3.2: Incorrect URL in Save Mission To API Node
Check: The "Save Mission To API" node URL should be:
{{ $node['Process Mission Data'].json.config.MISSION_API_URL }}/api/missions/mission-created
NOT:
{{ $node['Process Mission Data'].json.config.MISSION_API_URL + '/mission-created' }}
Issue 3.3: Missing missionId in Save Mission To API Body
Check: The "Save Mission To API" node body should include:
- Parameter:
missionId - Value:
{{ $node['Process Mission Data'].json.missionId }}
Issue 3.4: API Key Mismatch
Check: The API key in the "Save Mission To API" node header should match your N8N_API_KEY environment variable.
Fix: Use:
{{ $node['Process Mission Data'].json.config.N8N_API_KEY }}
Debug Workflow Errors
-
Check N8N Execution Logs:
- Go to N8N → Executions
- Find the failed execution
- Click on it to see which node failed
- Check the error message
-
Test Each Node Individually:
- Execute the workflow step by step
- Check each node's output
- Verify data is flowing correctly
📋 Complete Checklist
Environment Variables
N8N_API_KEYis set in.env.localor production environment- Value matches the API key used in N8N workflow
- Application has been restarted after adding the variable
N8N Workflow Configuration
- Workflow is ACTIVE (green toggle in N8N)
- Webhook path is:
mission-created - Webhook URL is:
https://brain.slm-lab.net/webhook/mission-created - "Process Mission Data" node includes
missionIdin output - "Save Mission To API" node URL is correct:
{{ MISSION_API_URL }}/api/missions/mission-created - "Save Mission To API" node includes
missionIdin body parameters - "Save Mission To API" node includes
x-api-keyheader with correct value
Testing
- Test webhook URL returns 200 (not 404)
- Create a test mission
- Check N8N execution logs for errors
- Verify mission IDs are saved to database after creation
🧪 Step-by-Step Testing
Step 1: Verify Environment Variable
# In your terminal (if running locally)
echo $N8N_API_KEY
# Or check in your application logs
# Should NOT see: "N8N_API_KEY is not set in environment variables"
Step 2: Test Webhook is Active
curl -X POST https://brain.slm-lab.net/webhook/mission-created \
-H "Content-Type: application/json" \
-d '{"test": "data"}'
Expected Results:
- ✅ 200/400/500 with workflow error: Webhook is active (workflow may fail due to invalid data, but webhook is registered)
- ❌ 404 with "webhook not registered": Webhook is NOT active → Activate workflow in N8N
Step 3: Test Mission Creation
- Create a mission via your frontend
- Check server logs - should NOT see:
- ❌ "N8N_API_KEY is not set"
- ❌ "404 webhook not registered"
- Check N8N execution logs - should see successful execution
- Check database - mission should have integration IDs saved
🔧 Quick Fix Commands
Add N8N_API_KEY to .env.local
# Add to .env.local file
echo "N8N_API_KEY=LwgeE1ntADD20OuWC88S3pR0EaO7FtO4" >> .env.local
# Restart your development server
# npm run dev
# or
# yarn dev
Verify Environment Variable is Loaded
Create a test endpoint to verify:
// app/api/test-n8n-config/route.ts
import { NextResponse } from 'next/server';
export async function GET() {
return NextResponse.json({
hasN8NApiKey: !!process.env.N8N_API_KEY,
n8nWebhookUrl: process.env.N8N_WEBHOOK_URL || 'https://brain.slm-lab.net/webhook/mission-created',
missionApiUrl: process.env.NEXT_PUBLIC_API_URL
});
}
Then visit: http://localhost:3000/api/test-n8n-config
📝 Summary of Fixes
-
Add
N8N_API_KEYto environment variables- File:
.env.local(development) or production environment - Value: Your actual N8N API key
- Restart application after adding
- File:
-
Activate N8N Workflow
- Open workflow in N8N
- Click "Active" toggle (should be green/on)
- Verify webhook is registered
-
Fix Workflow Configuration
- Ensure "Save Mission To API" URL is correct
- Ensure
missionIdis included in body - Check N8N execution logs for specific errors
🚨 If Still Not Working
Check N8N Execution Logs
- Go to N8N → Executions
- Find the latest failed execution
- Click on it
- Check which node failed
- Look at the error message
- Fix the specific issue
Common Additional Issues
- Network connectivity: N8N can't reach your API
- CORS issues: If calling from browser
- Authentication: API key mismatch
- Data format: Body parameters don't match expected format
Document Created: $(date) Priority: CRITICAL - Blocks mission creation