8.7 KiB
N8N Save Mission To API Node - Fix Required
🔍 Problem Analysis
Based on the N8N workflow configuration you provided, I've identified TWO CRITICAL ISSUES:
❌ Issue 1: Incorrect URL
Current Configuration
URL: {{ $node['Process Mission Data'].json.config.MISSION_API_URL + '/mission-created' }}
What This Produces
MISSION_API_URL=https://hub.slm-lab.net(from your config)- Result:
https://hub.slm-lab.net/mission-created❌
Actual Endpoint
- Should be:
https://hub.slm-lab.net/api/missions/mission-created✅
Fix Required
URL: {{ $node['Process Mission Data'].json.config.MISSION_API_URL }}/api/missions/mission-created
Note: Remove the + operator and add /api/missions before /mission-created
❌ Issue 2: Missing missionId in Body
Current Configuration
Looking at your base.json, I can see the body parameters, but missionId is MISSING!
What the Endpoint Expects
From app/api/missions/mission-created/route.ts:
missionId⚠️ REQUIRED - Used to find the mission (preferred over name + creatorId)gitRepoUrl→ maps togiteaRepositoryUrlin databaseleantimeProjectId→ maps toleantimeProjectIdin databasedocumentationCollectionId→ maps tooutlineCollectionIdin databaserocketchatChannelId→ maps torocketChatChannelIdin databasecreatorId✅ (you have this)name✅ (you have this)
What the Endpoint Expects
From app/api/missions/mission-created/route.ts:
gitRepoUrl→ maps togiteaRepositoryUrlin databaseleantimeProjectId→ maps toleantimeProjectIdin databasedocumentationCollectionId→ maps tooutlineCollectionIdin databaserocketchatChannelId→ maps torocketChatChannelIdin databasemissionId✅ (you have this)creatorId✅ (you have this)name✅ (you have this)
What N8N Should Send
Body Parameters (in N8N HTTP Request node):
| Field Name | Value Expression |
|---|---|
name |
{{ $node['Process Mission Data'].json.missionProcessed.name }} |
niveau |
`{{ $node['Process Mission Data'].json.missionProcessed.niveau |
intention |
{{ $node['Process Mission Data'].json.missionProcessed.intention }} |
gitRepoUrl |
`{{ $node['Combine Results'].json.gitRepo?.html_url |
leantimeProjectId |
`{{ $node['Combine Results'].json.leantimeProject?.result?.[0] |
documentationCollectionId |
`{{ $node['Combine Results'].json.docCollection?.data?.id |
rocketchatChannelId |
`{{ $node['Combine Results'].json.rocketChatChannel?.channel?._id |
missionId |
{{ $node['Process Mission Data'].json.missionId }} |
creatorId |
{{ $node['Process Mission Data'].json.creatorId }} |
⚠️ CRITICAL: The field names must match exactly:
gitRepoUrl(notgitRepoorgiteaRepositoryUrl)leantimeProjectId(notleantimeProjectorleantimeId)documentationCollectionId(notdocCollectionoroutlineCollectionId)rocketchatChannelId(notrocketChatChannelorrocketChatChannelId)
✅ Complete Fix for N8N Node
Step 1: Fix the URL
In the "Save Mission To API" HTTP Request node:
Current (WRONG):
{{ $node['Process Mission Data'].json.config.MISSION_API_URL + '/mission-created' }}
Fixed (CORRECT):
{{ $node['Process Mission Data'].json.config.MISSION_API_URL }}/api/missions/mission-created
Step 2: Configure Body Parameters
In the "Save Mission To API" HTTP Request node, set Body Parameters:
Method: POST
Send Body: Yes
Body Content Type: JSON (or use Body Parameters)
Body Parameters (add each as a parameter):
-
Parameter Name:
nameValue:{{ $node['Process Mission Data'].json.missionProcessed.name }} -
Parameter Name:
niveauValue:{{ $node['Process Mission Data'].json.missionProcessed.niveau || 'default' }} -
Parameter Name:
intentionValue:{{ $node['Process Mission Data'].json.missionProcessed.intention }} -
Parameter Name:
gitRepoUrl⚠️ (MUST be this exact name) Value:{{ $node['Combine Results'].json.gitRepo?.html_url || '' }} -
Parameter Name:
leantimeProjectId⚠️ (MUST be this exact name) Value:{{ $node['Combine Results'].json.leantimeProject?.result?.[0] || '' }} -
Parameter Name:
documentationCollectionId⚠️ (MUST be this exact name) Value:{{ $node['Combine Results'].json.docCollection?.data?.id || '' }} -
Parameter Name:
rocketchatChannelId⚠️ (MUST be this exact name) Value:{{ $node['Combine Results'].json.rocketChatChannel?.channel?._id || '' }} -
Parameter Name:
missionId⚠️ MISSING - MUST ADD THIS Value:{{ $node['Process Mission Data'].json.missionId }} -
Parameter Name:
creatorIdValue:{{ $node['Process Mission Data'].json.creatorId }}
⚠️ CRITICAL: The missionId field is MISSING from your current configuration. The endpoint prefers missionId over name + creatorId for more reliable mission lookup.
Step 3: Verify Headers
Headers should include:
Content-Type:application/jsonx-api-key:{{ $node['Process Mission Data'].json.config.N8N_API_KEY }}
🧪 Testing the Fix
Test 1: Check URL
After fixing, the URL should resolve to:
https://hub.slm-lab.net/api/missions/mission-created
Test 2: Check Request Body
After fixing, the request body should look like:
{
"name": "Mission Name",
"niveau": "default",
"intention": "Mission description",
"gitRepoUrl": "https://gite.slm-lab.net/alma/repo-name",
"leantimeProjectId": "123",
"documentationCollectionId": "collection-id",
"rocketchatChannelId": "channel-id",
"missionId": "mission-uuid",
"creatorId": "user-uuid"
}
Test 3: Check Server Response
The endpoint should return:
{
"success": true,
"message": "Mission updated successfully",
"mission": {
"id": "mission-uuid",
"name": "Mission Name",
"giteaRepositoryUrl": "https://gite.slm-lab.net/alma/repo-name",
"leantimeProjectId": "123",
"outlineCollectionId": "collection-id",
"rocketChatChannelId": "channel-id"
}
}
📋 Verification Checklist
After applying the fix:
- URL is correct:
{{ MISSION_API_URL }}/api/missions/mission-created - Body includes
gitRepoUrlfield (notgitRepoorgiteaRepositoryUrl) - Body includes
leantimeProjectIdfield (notleantimeProjectorleantimeId) - Body includes
documentationCollectionIdfield (notdocCollectionoroutlineCollectionId) - Body includes
rocketchatChannelIdfield (notrocketChatChannel) - Body includes
missionIdfield - Body includes
creatorIdfield - Headers include
x-api-key - Headers include
Content-Type: application/json - Test execution shows 200 OK response
- Database shows IDs saved after mission creation
🔍 Debugging
If Still Not Working
-
Check N8N Execution Logs:
- Look at "Save Mission To API" node execution
- Check the actual URL being called
- Check the actual body being sent
- Check the response status code
-
Check Server Logs:
- Look for
/api/missions/mission-createdendpoint calls - Check for 404 errors (wrong URL)
- Check for 400 errors (missing fields)
- Check for 401 errors (wrong API key)
- Look for
-
Test Manually:
curl -X POST https://hub.slm-lab.net/api/missions/mission-created \ -H "Content-Type: application/json" \ -H "x-api-key: YOUR_N8N_API_KEY" \ -d '{ "missionId": "test-mission-id", "name": "Test Mission", "creatorId": "test-user-id", "gitRepoUrl": "https://gite.slm-lab.net/alma/test", "leantimeProjectId": "123", "documentationCollectionId": "collection-456", "rocketchatChannelId": "channel-789" }'
📝 Summary
Two critical fixes required:
-
URL Fix: Change from:
{{ $node['Process Mission Data'].json.config.MISSION_API_URL + '/mission-created' }}To:
{{ $node['Process Mission Data'].json.config.MISSION_API_URL }}/api/missions/mission-created -
Add Missing
missionIdField: Add this parameter to the body:- Name:
missionId - Value:
{{ $node['Process Mission Data'].json.missionId }}
- Name:
Note: Your field names are already correct (gitRepoUrl, leantimeProjectId, etc.), but missionId is missing which is critical for reliable mission lookup.
After these fixes, the N8N workflow should successfully save integration IDs to the database, and mission deletion should work correctly.
Document Created: $(date) Priority: CRITICAL - Blocks mission deletion functionality