Skip to main content

Get current weather by city

Use the q query parameter on /data/2.5/weather to fetch real-time weather observations for a named city when you don't yet have latitude and longitude coordinates.

Prefer coordinates for production lookups

OpenWeatherMap's built-in city-name lookup (q) is a legacy convenience feature that relies on internal ranking when multiple places share a name. For unambiguous production queries, resolve place names first and use geographic coordinates.

Before running these examples, export your API key as OPENWEATHER_API_KEY. If you haven't created a key yet, see Get an API key.

Query by city name​

Pass the city name in q, set units=metric to receive temperatures in Celsius, and include your key in appid:

curl --get "https://api.openweathermap.org/data/2.5/weather" \
--data-urlencode "q=Paris" \
--data-urlencode "units=metric" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"

Encode multi-word city names​

City names containing spaces or diacritics—such as Rio de Janeiro, New York, or São Paulo—must be percent-encoded in the query string. Avoid concatenating raw user input into URLs by hand; let your HTTP client serialize query parameters automatically:

curl --get "https://api.openweathermap.org/data/2.5/weather" \
--data-urlencode "q=Rio de Janeiro" \
--data-urlencode "units=metric" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"

Disambiguate duplicate city names​

Hundreds of municipalities worldwide share identical names. Append comma-separated ISO 3166-1 alpha-2 country codes—and two-letter state codes for US cities—to target the exact jurisdiction you want.

Specify a country code​

Format q as {city},{country} to distinguish cities across countries, such as London,GB (United Kingdom) versus London,CA (Ontario, Canada):

# London, United Kingdom
curl --get "https://api.openweathermap.org/data/2.5/weather" \
--data-urlencode "q=London,GB" \
--data-urlencode "units=metric" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"

# London, Ontario, Canada
curl --get "https://api.openweathermap.org/data/2.5/weather" \
--data-urlencode "q=London,CA" \
--data-urlencode "units=metric" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"

Specify a US state and country code​

For cities in the United States, format q as {city},{state},{country}—for example, Portland,OR,US versus Portland,ME,US.

Always include US as the third segment when passing a US state code. A two-part query treats the second segment as an ISO country code: Ontario,CA targets Ontario in Canada (CA), whereas Ontario,CA,US targets Ontario in California (CA,US).

State codes apply only to the United States

OpenWeatherMap supports {state} codes exclusively for US locations (US). For cities in Canada, Australia, Brazil, or any other country, pass {city},{country} without a state or province segment.

# Portland, Oregon, United States
curl --get "https://api.openweathermap.org/data/2.5/weather" \
--data-urlencode "q=Portland,OR,US" \
--data-urlencode "units=metric" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"

# Portland, Maine, United States
curl --get "https://api.openweathermap.org/data/2.5/weather" \
--data-urlencode "q=Portland,ME,US" \
--data-urlencode "units=metric" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"

Localize weather descriptions​

Add the lang parameter to translate weather[0].description and the returned city name into the user's preferred language. Numeric condition codes (weather[0].id) and group names (weather[0].main) remain unchanged across languages, so branch your UI icon logic on weather[0].id rather than the translated description string:

curl --get "https://api.openweathermap.org/data/2.5/weather" \
--data-urlencode "q=Madrid,ES" \
--data-urlencode "units=metric" \
--data-urlencode "lang=es" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"