OpenWeatherMap API
Access real-time weather data, forecasts, air pollution reports, and historical weather information for any location globally.
Overview
API Plugin’s OpenWeatherMap API provides simple access to comprehensive weather data from around the world. Perfect for weather apps, travel services, outdoor event planning, smart home systems, and any application that needs reliable weather information.
Key benefits include:
- Current weather conditions
- 5-day weather forecasts
- Air pollution data
- Global coverage
- Multiple query options (city name, coordinates, zip code)
- Customizable units (metric, imperial)
- Multi-language support
- Comprehensive weather parameters
- Reliable data delivery
How to Setup
We assume you have signed up on API Plugin and are logged into the dashboard.
-
Get an OpenWeatherMap API Key:
- Create an account at OpenWeatherMap
- Go to your profile and generate an API key
- Copy your API key
-
Configure API:
- Go to API Plugin marketplace
- Select OpenWeatherMap API
- Input your API key
- Create API endpoint
Available Endpoints
- Current Weather
GET /v1/{appId}/{token}/current
Parameters:
q
: City name (e.g., “London,UK”)lat
&lon
: Geographic coordinateszip
: ZIP code (e.g., “94040,us”)units
: Units of measurement (standard, metric, imperial)lang
: Language code
Example Request:
/v1/{appId}/{token}/current?q=London,UK&units=metric
- 5-day Forecast
GET /v1/{appId}/{token}/forecast
Parameters:
q
: City name (e.g., “London,UK”)lat
&lon
: Geographic coordinateszip
: ZIP code (e.g., “94040,us”)units
: Units of measurement (standard, metric, imperial)lang
: Language codecnt
: Number of timestamps to return
Example Request:
/v1/{appId}/{token}/forecast?lat=51.5074&lon=-0.1278&units=metric
- Air Pollution Data
GET /v1/{appId}/{token}/air-pollution
Parameters:
lat
&lon
: Geographic coordinates (required)
Example Request:
/v1/{appId}/{token}/air-pollution?lat=40.7128&lon=-74.0060
- Weather by City ID
GET /v1/{appId}/{token}/by-id
Parameters:
id
: City ID (required)units
: Units of measurement (standard, metric, imperial)lang
: Language code
Example Request:
/v1/{appId}/{token}/by-id?id=2643743&units=metric
- One Call API
GET /v1/{appId}/{token}/onecall
Parameters:
lat
&lon
: Geographic coordinates (required)exclude
: Parts to exclude (current,minutely,hourly,daily,alerts)units
: Units of measurement (standard, metric, imperial)lang
: Language code
Example Request:
/v1/{appId}/{token}/onecall?lat=33.44&lon=-94.04&exclude=minutely,alerts&units=metric
Weather Data Interpretation
-
Weather Condition Codes:
- 2xx: Thunderstorm
- 3xx: Drizzle
- 5xx: Rain
- 6xx: Snow
- 7xx: Atmosphere (fog, haze)
- 800: Clear
- 80x: Clouds
-
Air Quality Index:
- 1: Good
- 2: Fair
- 3: Moderate
- 4: Poor
- 5: Very Poor
Example Code
// Get current weather
const getCurrentWeather = async (city) => {
try {
const response = await fetch(`/v1/{appId}/{token}/current?q=${city}&units=metric`);
const data = await response.json();
console.log(`Current temperature in ${data.name}: ${data.main.temp}°C`);
console.log(`Weather: ${data.weather[0].description}`);
console.log(`Humidity: ${data.main.humidity}%`);
return data;
} catch (error) {
console.error('Error fetching weather data:', error);
}
};
// Get 5-day forecast
const getForecast = async (lat, lon) => {
try {
const response = await fetch(`/v1/{appId}/{token}/forecast?lat=${lat}&lon=${lon}&units=metric`);
const data = await response.json();
// Process forecast data
const dailyForecasts = data.list.filter((item) => item.dt_txt.includes('12:00:00'));
dailyForecasts.forEach((day) => {
console.log(`Date: ${day.dt_txt.split(' ')[0]}`);
console.log(`Temperature: ${day.main.temp}°C`);
console.log(`Weather: ${day.weather[0].description}`);
console.log('-------------------');
});
return data;
} catch (error) {
console.error('Error fetching forecast data:', error);
}
};