# N8N Wrong URL - Getting HTML Instead of JSON ## ๐Ÿ” Problem Identified **N8N "Save Mission To API" node is receiving HTML (404 page) instead of JSON response.** ### What N8N Receives ```html ...

404

This page could not be found.

... ``` **This is a Next.js 404 page**, not the API endpoint response! --- ## โŒ Root Cause **The URL in N8N is pointing to a Next.js page route instead of the API endpoint.** ### Current (WRONG) URL N8N is probably calling: ``` https://hub.slm-lab.net/mission-created ``` This matches Next.js route: `app/[section]/page.tsx` - Next.js tries to find a page at `/mission-created` - No page exists, so it returns 404 HTML page - N8N receives HTML instead of JSON ### Correct URL Should be: ``` https://hub.slm-lab.net/api/missions/mission-created ``` This matches API route: `app/api/missions/mission-created/route.ts` - Next.js routes to the API endpoint - Returns JSON response - N8N receives proper JSON --- ## โœ… Solution ### Fix the URL in N8N "Save Mission To API" Node **Current (WRONG)**: ``` {{ $node['Process Mission Data'].json.config.MISSION_API_URL + '/mission-created' }} ``` **Or**: ``` {{ $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-by-Step Fix 1. **Open N8N workflow** 2. **Find "Save Mission To API" node** 3. **Click on it to edit** 4. **In the URL field**, 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 ``` 5. **Save the node** 6. **Activate the workflow** (if not already active) 7. **Test by creating a new mission** --- ## ๐Ÿงช Verification ### After Fix, N8N Should Receive **Expected JSON Response**: ```json { "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-456", "rocketChatChannelId": "channel-789" } } ``` **NOT HTML**: ```html ... ``` ### Check Server Logs After fix, you should see: ``` Mission Created Webhook Received Received mission-created data: { ... } Found mission: { id: "...", name: "..." } Updating giteaRepositoryUrl: ... Mission updated successfully ``` --- ## ๐Ÿ“‹ Complete URL Configuration ### In N8N "Save Mission To API" Node **URL**: ``` {{ $node['Process Mission Data'].json.config.MISSION_API_URL }}/api/missions/mission-created ``` **Method**: `POST` **Headers**: - `Content-Type`: `application/json` - `x-api-key`: `{{ $node['Process Mission Data'].json.config.N8N_API_KEY }}` **Body Parameters**: - `missionId`: `{{ $node['Process Mission Data'].json.missionId }}` - `name`: `{{ $node['Process Mission Data'].json.missionProcessed.name }}` - `creatorId`: `{{ $node['Process Mission Data'].json.creatorId }}` - `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 || '' }}` --- ## ๐Ÿ” Why This Happens ### Next.js Routing Next.js has two types of routes: 1. **Page Routes** (`app/[section]/page.tsx`): - Matches: `/mission-created` - Returns: HTML page - Used for: Frontend pages 2. **API Routes** (`app/api/missions/mission-created/route.ts`): - Matches: `/api/missions/mission-created` - Returns: JSON response - Used for: API endpoints ### The Problem When N8N calls `/mission-created`: - Next.js matches it to `app/[section]/page.tsx` - `section = "mission-created"` - Page doesn't exist in `menuItems` - Returns 404 HTML page When N8N calls `/api/missions/mission-created`: - Next.js matches it to `app/api/missions/mission-created/route.ts` - Executes the API handler - Returns JSON response --- ## โœ… Summary **Problem**: N8N receives HTML 404 page instead of JSON **Cause**: URL is missing `/api/missions` prefix **Fix**: Change URL from: ``` {{ MISSION_API_URL }}/mission-created ``` To: ``` {{ MISSION_API_URL }}/api/missions/mission-created ``` **After Fix**: N8N will receive JSON response and IDs will be saved to database. --- **Document Created**: $(date) **Priority**: CRITICAL - Blocks integration IDs from being saved