Locations

Location keys

A location key is a unique identifier for a precise geographic location. Use one of the Locations API endpoints to find a location key. It is required for most API endpoints, including:

Find a location key

To get a location key, use one of the Location search endpoints. Below are some examples:

Use caseEndpoint
City name search/locations/v1/cities/search
Postal code search/locations/v1/postalcodes/search
Points of interest search/locations/v1/poi/search
Cities by latitude/longitude/locations/v1/cities/geoposition/search
IP-based auto-detect/locations/v1/cities/ipaddress

Try a city search to get started:

const url = "https://dataservice.accuweather.com/locations/v1/cities/search?q=San+Francisco"; const response = await fetch(url, { headers: { "Authorization": "Bearer YOUR_API_KEY", "Accept-Encoding": "gzip", }, }); const data: Record<string, unknown>[] = await response.json();

Response:

JSONCode
[ { "Version": 1, "Key": "347629", "Type": "City", "Rank": 35, "LocalizedName": "San Francisco", "EnglishName": "San Francisco", "PrimaryPostalCode": "94103", ... } ]

➡️ 347629 is the location key for San Francisco, CA, US.

Use a location key

Use the location key we just found in other API endpoints:

const url = "https://dataservice.accuweather.com/currentconditions/v1/347629"; const response = await fetch(url, { headers: { "Authorization": "Bearer YOUR_API_KEY", "Accept-Encoding": "gzip", }, }); const data: Record<string, unknown>[] = await response.json();

This returns the current conditions for San Francisco, CA.

Last modified on