MagicMirrorOrg/MagicMirror · error · Error

apiKey is required

Error message

apiKey is required

What it means

WeatherAPI.com is a commercial API that requires an API key. #validateConfig throws this when config.apiKey is missing, null, or consists only of whitespace, aborting initialize before any network call is made.

Solutions

  1. Sign up at weatherapi.com and put the returned key in config: { apiKey: "<your-key>" }.
  2. If the key comes from an env/config file, verify it resolves to a non-empty trimmed string (Log the length, never the value).
  3. Make sure you are using a weatherapi.com key, not a key from a different provider.
  4. Restart MagicMirror after adding the key so the module re-initializes.

Example fix

// before
config: {
  weatherProvider: "weatherapi",
  type: "current"
}
// after
config: {
  weatherProvider: "weatherapi",
  type: "current",
  apiKey: "abc123yourkey"
}
Defensive patterns

Strategy: validation

Validate before calling

if (typeof config.apiKey !== "string" || config.apiKey.trim() === "") {
  throw new Error("weatherapi: set apiKey in the module config before starting MagicMirror");
}

Type guard

function hasApiKey(config) {
  return typeof config.apiKey === "string" && config.apiKey.trim().length > 0;
}

Prevention

When it happens

Trigger: apiKey not set in module config, set to empty string "" or " ", or set to a non-string falsy value (0, false, null) when the module initializes.

Common situations: Fresh MagicMirror install with a sample weather config and no key; key stored in an env var or custom.js that fails to resolve to a non-empty string; users confusing weatherapi.com's key with an OpenWeatherMap key.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of MagicMirrorOrg/MagicMirror@4b4a59534f (2026-08-31). Data as JSON: /api/errors/12f9620e47631a80. Report an issue: GitHub.

Appendix: source

Thrown at defaultmodules/weather/providers/weatherapi.js:62

	stop () {
		if (this.fetcher) {
			this.fetcher.clearTimer();
		}
	}

	#validateConfig () {
		this.config.type = `${this.config.type ?? ""}`.trim().toLowerCase();

		if (this.config.type === "forecast") {
			this.config.type = "daily";
		}

		if (!["hourly", "daily", "current"].includes(this.config.type)) {
			throw new Error(`Unknown weather type: ${this.config.type}`);
		}

		if (!this.config.apiKey || `${this.config.apiKey}`.trim() === "") {
			throw new Error("apiKey is required");
		}

		if (!Number.isFinite(this.config.lat) || !Number.isFinite(this.config.lon)) {
			throw new Error("Latitude and longitude are required");
		}
	}

	#initializeFetcher () {
		const url = this.#getUrl();

		this.fetcher = new HTTPFetcher(url, {
			reloadInterval: this.config.updateInterval,
			headers: { "Cache-Control": "no-cache" },
			logContext: "weatherprovider.weatherapi"
		});

		this.fetcher.on("response", async (response) => {
			try {

View on GitHub (pinned to 4b4a59534f)