Zie619/n8n-workflows · error · Error

The Google API Key is missing.

Error message

The Google API Key is missing.

What it means

Thrown by the same 'Create YouTube API URL' Code node as the empty-video-ID guard, but for the second required input: google_api_key. The node expects the API key to arrive in the input JSON (dynamically passed in), not from n8n credentials, and fails fast before constructing the URL when it is falsy.

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. Verify the upstream trigger/node actually outputs google_api_key in its JSON and wire that field through any intermediate Set/Merge nodes.
  2. Better: stop passing the key through item data. Read it from an n8n environment variable ($env.GOOGLE_API_KEY) or a credentials-based HTTP Request node so it never travels through the payload.
  3. Log Object.keys($input.first().json) (never the key value) to confirm the field name and presence.
  4. Return a clear 'API key not configured' message to an error branch rather than throwing, if user-facing forms can trigger this.

Example fix

// before
const GOOGLE_API_KEY = item.json.google_api_key;
if (!GOOGLE_API_KEY) {
  throw new Error('The Google API Key is missing.');
}

// after (key from environment, not payload)
const GOOGLE_API_KEY = $env.GOOGLE_API_KEY;
if (!GOOGLE_API_KEY) {
  throw new Error('GOOGLE_API_KEY is not configured in the n8n environment.');
}
Defensive patterns

Strategy: validation

Validate before calling

const GOOGLE_API_KEY = item.json.google_api_key || $env.GOOGLE_API_KEY;
if (!GOOGLE_API_KEY) {
  return [{ json: { error: 'YouTube API key not configured' } }];
}

Type guard

function hasApiKey(item, env) {
  return Boolean(item?.json?.google_api_key || env?.GOOGLE_API_KEY);
}

Prevention

When it happens

Trigger: The form/webhook payload lacks google_api_key, the field is empty, or the key was moved to n8n credentials/environment variables while this node still reads item.json.google_api_key. Also fires when an upstream node strips or renames the key field.

Common situations: Refactor where the API key was migrated to $env or a credentials object but this Code node was not updated; form payload shape changed; a security pass removed the key from the payload as a secret-hygiene fix without adding an alternative source.

Related errors


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