telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

[inputs.openweathermap] Version 2.5 of the API is no longer supported

Open BokuNoGF opened this issue 3 months ago • 7 comments

Relevant telegraf.conf

[[inputs.openweathermap]]
  ## OpenWeatherMap API key.
  app_id = "xxxxxxxxxxxxxxxxxxxxxxxxxx"

  ## City ID's to collect weather data from.
  city_id = ["0000000"]

  ## Language of the description field. Can be one of "ar", "bg",
  ## "ca", "cz", "de", "el", "en", "fa", "fi", "fr", "gl", "hr", "hu",
  ## "it", "ja", "kr", "la", "lt", "mk", "nl", "pl", "pt", "ro", "ru",
  ## "se", "sk", "sl", "es", "tr", "ua", "vi", "zh_cn", "zh_tw"
  lang = "en"

  ## APIs to fetch; can contain "weather" or "forecast".
  fetch = ["weather", "forecast"]

  ## OpenWeatherMap base URL
  # base_url = "https://api.openweathermap.org/"

  ## Timeout for HTTP response.
  # response_timeout = "5s"

  ## Preferred unit system for temperature and wind speed. Can be one of
  ## "metric", "imperial", or "standard".
  units = "imperial"

  ## Query interval; OpenWeatherMap weather data is updated every 10
  ## minutes.
  interval = "10m"

Logs from Telegraf

2025-08-29T05:40:00Z E! [inputs.openweathermap] Error in plugin: querying "https://api.openweathermap.org/data/2.5/group?APPID=xxxxxxxxxxxxxxxxx&id=0000000&lang=en&units=imperial" failed: https://api.openweathermap.org/data/2.5/group?APPID=xxxxxxxxxxxxxxxxx&id=0000000&lang=en&units=imperial returned HTTP status 401 Unauthorized

System info

telegraf:1.35.4-alpine, Debian 13, k8s v1.33.3

Docker

No response

Steps to reproduce

  1. Attempt to create and run the openweathermap input with any valid configuration

Expected behavior

Input is able to hit and retrieve data from OpenWeathermap

Actual behavior

Telegraf returns a 401 error as version 2.5 of the API is no longer being hosted

Additional info

It seems that access to the 2.5 version of the API has been closed since June 2024, but the endpoint was still functional until today: https://openweathermap.org/one-call-transfer

Seems that the input will need to be fixed to utilize the 3.0 version of the API, as described in the linked blog post.

BokuNoGF avatar Aug 29 '25 05:08 BokuNoGF

Confirmed. Hopefully this is a quick & easy fix.

MWP avatar Aug 30 '25 02:08 MWP

You can fix by configuring query_style with individual (default is batch which shouldn't be used and is here only for backward compatibility) https://github.com/influxdata/telegraf/tree/master/plugins/inputs/openweathermap

Dalvany avatar Aug 31 '25 08:08 Dalvany

It seems like this requires an new input.openweathermap_v2 implementation for switching to the v3 API as e.g. the city-IDs will not work anymore for the new API...

srebhan avatar Sep 09 '25 09:09 srebhan

Anyone willing to contribute a plugin?

srebhan avatar Sep 09 '25 09:09 srebhan

I might give it a try when if I find the time

Dalvany avatar Sep 20 '25 08:09 Dalvany

API v2.5 still works with the city IDs but it seems only a single location per query can be used (regardless of whether it's lat/lon, name, zip, or ID). API v3 also does not have a group selector.

Working, with free account:

https://api.openweathermap.org/data/2.5/weather?id={id}&appid={APPID}

Perhaps the plugin can be refactored to make multiple queries, one per location.

ludditus-RPI avatar Sep 29 '25 20:09 ludditus-RPI

You can simply add multiple instances/configurations of the plugin to your Telegraf configuration, e.g.

[[inputs.openweathermap]]
  app_id = "..."
  city_id = ["4219762"]
  lang = "en"
  fetch = ["weather"]
  base_url = "https://api.openweathermap.org/"
  interval = "10m"
  query_style = "individual"

[[inputs.openweathermap]]
  app_id = "..."
  city_id = ["264371"]
  lang = "en"
  fetch = ["weather"]
  base_url = "https://api.openweathermap.org/"
  interval = "10m"
  query_style = "individual"

And they'll all run at once. Do note that each one is a separate API request, so if you're running into limits per minute, you can somewhat work around this by configuring a collection jitter of say, 9 minutes.

colebow avatar Nov 21 '25 17:11 colebow