9 API SMHI
b23albst edited this page 2026-04-29 08:57:01 +00:00

API SMHI

SMHI has two different API's. METOBS and SNOW1gv1. This page will cover them both.

METOBS is an api for actual observed weather data (current and previous) and SNOW is an api for forecast data (current and future).

METOBS API

Fetching data

When fetching data from the api, a couple arguments are needed. These are:

  • Version
  • Parameter
    • These are in the form of codes corresponding to different types of data, see METOBS parameters
  • Station
  • Period

Example request: https://opendata-download-metobs.smhi.se/api/version/latest/parameter/1/station/83230/period/latest-day/data.json

The useSMHIObservations hook uses this api and takes the parameters "parameter", "station" and "period"

Data received

In the received json data, there are JSON objects with information about the different arguments (eg. the station-object contains the name of the station). Apart from this there is always an array called "value" that contains objects with the actual observation data. The number of objects in value differ depending on the period argument, but the most recent observation is always in the object at the highest index. The content of the objects in value can differ depending on the parameter used, but they usually contain:

  • value - The actual observation data, such as temperature, wind strength, etc.
  • date - Unix timestamp of the observation time.
  • quality - Reliability of the observation.

SNOW API

Fetching data

The SNOW api uses coordinates to retrieve forecast data.

Example request: https://opendata-download-metfcst.smhi.se/api/category/snow1g/version/1/geotype/point/lon/14.0298/lat/58.4601/data.json

The useSMHIForecast hook uses this api and takes the parameters longitude and latitude.

Data received

In the retrieved json data, there is an array called timeSeries which contains objects for all weather forecasts for the specified coordinates. The forecasts are ordered chronologically, with index 0 as the forecast for the current hour (when the data was fetched) and higher indexes being later forecasts.

At each index of timeSeries, there is an object called data, that contains all forecast data for that particular time as key-value pairs . An explanation of these can be found here.