NeahNew/N8N_WRONG_URL_FIX.md
2026-01-09 11:19:32 +01:00

4.7 KiB

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

<!DOCTYPE html>
<html lang="fr">
  ...
  <h1>404</h1>
  <h2>This page could not be found.</h2>
  ...
</html>

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:

{
  "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:

<!DOCTYPE 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