Meteorologisk Institutt

Weather

Using the MET Norway Weather API

The MET Norway Weather API is a publicly available API that offers data related to the weather in Norway. This API can be accessed using HTTP GET and POST requests, and it returns data in JSON and XML formats.

Getting Started

To use the MET Norway Weather API, you will need an API key. You can obtain an API key by registering on the API website.

Once you have an API key, you can start making requests to the API. You can use any programming language that supports HTTP requests and JSON/XML parsing, but for this tutorial, we will be using JavaScript.

Example Code

The following code shows how to make a basic weather forecast request using JavaScript:

const apiKey = 'YOUR_API_KEY';
const city = 'Oslo';

const requestUrl = `https://api.met.no/weatherapi/locationforecast/2.0/compact?latlon=${city}`;

const response = await fetch(requestUrl, {
  headers: { 'Authorization': `Bearer ${apiKey}` },
});

const data = await response.json();

console.log(data.properties.timeseries[0].data.instant.details.air_temperature);

In this example code, we first set our API key and the city we want to get a weather forecast for. We then construct the request URL by concatenating the base URL for the MET Norway Weather API with the latlon parameter set to our city.

We then use the fetch function to make the HTTP request to the API, passing in our API key as a bearer token in the Authorization header.

Finally, we parse the response as JSON using the json method of the response object, and we log the air temperature data for the current time in the city.

Conclusion

The MET Norway Weather API is a useful tool for obtaining weather-related data in Norway. With the code examples provided in this tutorial, you should be able to get started with making requests to this API using JavaScript.

Related APIs in Weather