Getting started overview

Integrating with the Meteorologisk Institutt (MET Norway) API provides access to weather data for various applications. This guide outlines the process from account creation to executing a first successful API call. The MET Norway API is primarily intended for retrieving location-based weather forecasts and related meteorological data, with usage policies that differentiate between non-commercial and commercial applications.

Before making requests, users should familiarize themselves with the Meteorologisk Institutt terms of service. The service is free for non-commercial use and for limited commercial purposes, requiring proper attribution. For commercial use exceeding these limits, direct contact with Meteorologisk Institutt for licensing information is necessary. The API supports various data types, but the Locationforecast API 2.0 is a common starting point for obtaining detailed weather predictions.

Here is a quick reference for the initial setup:

Step What to Do Where
1. Review Terms Understand usage policies and attribution requirements Meteorologisk Institutt Terms of Service
2. Create Account Register on the developer portal Meteorologisk Institutt Registration Page
3. Obtain Credentials Your user agent string acts as an identifier After registration, noted in documentation
4. Construct Request Build your first API call URL Locationforecast API 2.0 Documentation
5. Make Call Execute the request using a tool or code Command line (cURL), browser, or programming language

Create an account and get keys

Unlike many APIs that rely on API keys or tokens for authentication, Meteorologisk Institutt primarily uses a user-agent string for identification and adherence to its terms of service. While a formal 'key' generation process is not required, creating an account on the developer portal is the initial step to access documentation, stay informed about API updates, and ensure compliance with usage guidelines.

  1. Navigate to the Developer Portal: Begin by visiting the official Meteorologisk Institutt developer portal.

  2. Register for an Account: Look for a 'Register' or 'Sign Up' option. You will typically need to provide an email address, create a password, and agree to the terms of use. Confirm your email address if prompted.

  3. Understand User-Agent Requirements: Meteorologisk Institutt requires all API requests to include a unique and descriptive User-Agent header as detailed in their request guidelines. This header should identify your application or service, including a contact email address. For example: User-Agent: MyWeatherApp/1.0 ([email protected]).

    This User-Agent string serves as your identifier to Meteorologisk Institutt. It is crucial for them to monitor usage, enforce terms, and contact you if necessary. There is no separate API key or token to generate from a dashboard. The responsibility falls on the developer to implement the User-Agent header correctly in every request.

  4. Review Rate Limits: While specific numeric rate limits are not prominently advertised as fixed values, Meteorologisk Institutt generally encourages caching data and making requests only as frequently as needed. Excessive requests without a valid use case may result in temporary or permanent blocking of your User-Agent. Adhering to the request guidelines for proper User-Agent use and responsible querying is key to maintaining access.

Your first request

After understanding the User-Agent requirement and registering, you can make your first API call. This example uses the Locationforecast API 2.0 to retrieve weather data for a specific location. We will use the coordinates for Oslo, Norway (latitude 59.91, longitude 10.75).

Using cURL (Command Line)

cURL is a widely available command-line tool for making HTTP requests and is excellent for testing APIs quickly. Most Unix-like systems and Windows (via WSL or Git Bash) have it pre-installed. For Windows users without these, downloading cURL for Windows is an option.

curl -v \
  --header "User-Agent: MyFirstWeatherApp/1.0 ([email protected])" \
  "https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=59.91&lon=10.75"

Replace [email protected] with your actual email address. The -v flag provides verbose output, showing request and response headers, which can be useful for debugging.

Using a Web Browser

You can also test the API directly in your web browser, though it won't allow easy modification of the User-Agent header. This method is primarily useful for verifying that the endpoint returns data.

  1. Open your web browser.
  2. Paste the following URL into the address bar and press Enter:
    https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=59.91&lon=10.75
  3. The browser will display the JSON response directly. Note that without a proper User-Agent header, your requests might be subject to stricter rate limiting or eventual blocking if used heavily.

Expected JSON Response (partial)

A successful request will return a JSON object containing weather forecast data. The structure includes metadata and a series of time series data points. Here's an abbreviated example:

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [
      10.75,
      59.91,
      0
    ]
  },
  "properties": {
    "meta": {
      "updated_at": "2023-10-27T10:00:00Z",
      "units": {
        "air_pressure_at_sea_level": "hPa",
        "air_temperature": "celsius",
        "cloud_area_fraction": "%",
        "relative_humidity": "%",
        "wind_from_direction": "degrees",
        "wind_speed": "m/s"
      }
    },
    "timeseries": [
      {
        "time": "2023-10-27T10:00:00Z",
        "data": {
          "instant": {
            "details": {
              "air_pressure_at_sea_level": 1013.9,
              "air_temperature": 7.8,
              "cloud_area_fraction": 75.3,
              "relative_humidity": 85.1,
              "wind_from_direction": 270.0,
              "wind_speed": 3.5
            }
          },
          "next_12_hours": {
            "summary": {
              "symbol_code": "cloudy"
            }
          },
          "next_1_hours": {
            "summary": {
              "symbol_code": "partlycloudy_day"
            },
            "details": {
              "precipitation_amount": 0.0
            }
          },
          "next_6_hours": {
            "summary": {
              "symbol_code": "cloudy"
            },
            "details": {
              "precipitation_amount": 0.2
            }
          }
        }
      }
      // ... more timeseries data
    ]
  }
}

This response structure provides current conditions and forecasts for various time intervals. You can parse this JSON data in your application to extract relevant weather information.

Common next steps

After successfully retrieving your first weather forecast, consider these steps to further integrate Meteorologisk Institutt data into your application:

  1. Explore Other Endpoints: Meteorologisk Institutt offers several APIs beyond Locationforecast. Depending on your project's needs, investigate the Textforecast API for human-readable forecasts, the Nowcast API for very short-term precipitation, or the Frost API for historical and observation data relevant to research and specific niche applications. Each API has distinct documentation and usage patterns.

  2. Implement Caching: To adhere to Meteorologisk Institutt's recommended usage and avoid unnecessary requests, implement robust caching for API responses. Weather data, especially forecasts, doesn't change instantaneously. Caching responses for an appropriate duration (e.g., 5-15 minutes for current conditions, longer for daily forecasts) reduces load on the API and improves your application's performance. Refer to the Expires and Cache-Control headers in API responses for guidance on optimal caching strategies. For general caching principles, the Cloudflare documentation on caching concepts provides a good overview.

  3. Error Handling: Design your application to gracefully handle API errors. Common issues include network problems, invalid coordinates, or rate limit exceedances. The API will return standard HTTP status codes (e.g., 400 Bad Request, 403 Forbidden, 429 Too Many Requests, 500 Internal Server Error). Implement logic to detect these codes and provide informative feedback to users or retry requests after an appropriate backoff period.

  4. Dynamic Location Input: Instead of hardcoding latitude and longitude, consider integrating a mechanism for users to input locations (e.g., search bar with a geocoding service) or using their device's location services to fetch dynamic weather data.

  5. Attribution Implementation: Ensure your application prominently displays the required attribution for Meteorologisk Institutt data, typically stating "Weather data from Meteorologisk Institutt" or similar, with a link to their homepage, as specified in their terms of service.

Troubleshooting the first call

Encountering issues during your first API call is common. Here are some troubleshooting tips for common problems:

  • HTTP 400 Bad Request:

    • Cause: Often due to malformed URL parameters (e.g., incorrect latitude/longitude format, missing required parameters).
    • Solution: Double-check the URL against the Locationforecast API 2.0 documentation. Ensure latitude and longitude are valid decimal numbers and that all necessary parameters are present.
  • HTTP 403 Forbidden:

    • Cause: Missing or invalid User-Agent header, or your IP address has been temporarily blocked due to excessive requests.
    • Solution: Verify that your User-Agent header is correctly formatted and includes your application name and contact email (e.g., MyWeatherApp/1.0 ([email protected])). Ensure you are making requests within reasonable limits. If you suspect a block, wait a while before retrying. Refer to the Meteorologisk Institutt request guidelines.
  • HTTP 429 Too Many Requests:

    • Cause: You have exceeded the implicit rate limits set by Meteorologisk Institutt.
    • Solution: Implement caching for your API responses to reduce the frequency of requests. Introduce delays between successive calls if you are making many requests in a short period. Review your application's fetching logic to ensure it's not requesting data more often than necessary.
  • No Data / Empty Response:

    • Cause: The API call might be successful, but the location might not have available data, or there's an issue with how you're parsing the response.
    • Solution: Verify the coordinates are for a valid geographical location with weather data. Check your code's JSON parsing logic to ensure it correctly handles the API's response structure. Use tools like jsonlint.com or IDE-integrated JSON formatters to validate the response structure.
  • Network Errors (e.g., connection refused):

    • Cause: Local network issues, firewall blocking, or the API server is temporarily unavailable.
    • Solution: Check your internet connection. Ensure no local firewall rules are preventing your application from accessing api.met.no. Check the Meteorologisk Institutt developer portal or social media for any service status updates.