Zie619/n8n-workflows · error · Error

The video ID parameter is empty.

Error message

The video ID parameter is empty.

What it means

Thrown by the 'Create YouTube API URL' Code node before any HTTP call is made. The node reads video_id and google_api_key from the first input item (produced by an upstream form trigger) and refuses to build the YouTube Data API URL when video_id is falsy. This is a deliberate fail-fast guard, not a YouTube API error.

Source

Thrown at workflows/Code/1313_Code_HTTP_Automation_Webhook.json:639

            }
          ]
        },
        "responseMode": "lastNode",
        "formDescription": "This workflow allows you to extract various types of actionable information from YouTube videos that is audience specific using dynamically composed prompts."
      },
      "typeVersion": 2.2,
      "notes": "This formTrigger node performs automated tasks as part of the workflow."
    },
    {
      "id": "c63d236c-99d5-43f6-825e-836ddd41ad6f",
      "name": "Create YouTube API URL",
      "type": "n8n-nodes-base.code",
      "position": [
        3100,
        100
      ],
      "parameters": {
        "jsCode": "// Define the base URL for the YouTube Data API\nconst BASE_URL = '{{ $env.API_BASE_URL }}';\n\n// Get the first input item\nconst item = $input.first();\n\n// Extract the videoId and google_api_key from the input JSON\nconst VIDEO_ID = item.json.video_id;\nconst GOOGLE_API_KEY = item.json.google_api_key; // Dynamically retrieve API key\n\nif (!VIDEO_ID) {\n  throw new Error('The video ID parameter is empty.');\n}\n\nif (!GOOGLE_API_KEY) {\n  throw new Error('The Google API Key is missing.');\n}\n\n// Construct the API URL with the video ID and dynamically retrieved API key\nconst youtubeUrl = `${BASE_URL}?part=snippet,contentDetails,status,statistics,player,topicDetails&id=${VIDEO_ID}&key=${GOOGLE_API_KEY}`;\n\n// Return the constructed URL\nreturn [\n  {\n    json: {\n      youtubeUrl: youtubeUrl,\n    },\n  },\n];\n"
      },
      "typeVersion": 2,
      "notes": "This code node performs automated tasks as part of the workflow."
    },
    {
      "id": "17daf9d1-4bee-4632-b929-0696e71b9fa2",
      "name": "Get YouTube Video Details",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3440,
        100
      ],
      "parameters": {
        "url": "{{ $env.BASE_URL }}",
        "options": {}
      },
      "typeVersion": 4.2,
      "notes": "This httpRequest node performs automated tasks as part of the workflow."

View on GitHub (pinned to 94007c1445)

Solutions

  1. Make video_id a required field on the form/webhook trigger and resubmit with the 11-character YouTube video ID.
  2. Log $input.first().json in the node to confirm the exact payload shape and field name the upstream node emits.
  3. Normalize input defensively: trim the value and, if a full URL was pasted, extract the ID with a regex before validating.
  4. Add an IF/error branch before this node that returns a friendly 'video ID required' response to the submitter instead of a thrown error.

Example fix

// before
const VIDEO_ID = item.json.video_id;
if (!VIDEO_ID) {
  throw new Error('The video ID parameter is empty.');
}

// after
const raw = (item.json.video_id ?? item.json.videoId ?? '').toString().trim();
const VIDEO_ID = raw.match(/(?:v=|youtu\.be\/|shorts\/)([\w-]{11})/)?.[1] || (raw.length === 11 ? raw : '');
if (!VIDEO_ID) {
  throw new Error(`The video ID parameter is empty or invalid. Got: ${JSON.stringify(raw)}`);
}
Defensive patterns

Strategy: validation

Validate before calling

const raw = String(item.json.video_id ?? '').trim();
const VIDEO_ID = raw.match(/(?:v=|youtu\.be\/|shorts\/)([\w-]{11})/)?.[1] || (raw.length === 11 ? raw : '');
if (!VIDEO_ID) {
  return [{ json: { error: 'video_id required: submit the 11-character YouTube video ID or a full URL' } }];
}

Type guard

function extractYouTubeId(v) {
  const s = String(v ?? '').trim();
  if (/^[\w-]{11}$/.test(s)) return s;
  return s.match(/(?:v=|youtu\.be\/|shorts\/|embed\/)([\w-]{11})/)?.[1] ?? null;
}

Prevention

When it happens

Trigger: The form/webhook submission omits the video_id field, sends it empty, or sends it under a different key (videoId, url instead of video_id). Also fires when a full YouTube URL is pasted instead of the bare 11-character ID, only if the field name mismatches — a pasted URL in video_id would pass this guard but fail later at the API.

Common situations: Form field renamed or remapped in the n8n Form Trigger; user submits without filling the field (field not marked required); upstream node outputs a different JSON shape (e.g. data nested under body or query); whitespace-only input.

Related errors


AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15). Data as JSON: /api/errors/2739875191879fe0. Report an issue: GitHub.