Weather Forecast API
Purpose
The Weather Forecast API delivers current and forecasted point-based weather conditions.
Request data for Hourly Forecasts
HTTPS method: GET
- Constants and parameters enclosed in curly brackets must be replaced with their values.
- Please see the following Request parameters section with the required and optional parameters tables for their values. The generic request format is as follows.
URL format
https://{baseURL}/weatherforecast/{version}/hourly?lat={latitude}&lon={longitude}&forecastHours={number_of_hours}&key={Your_API_Key}
Example
https://api.tomtom.com/weatherforecast/v1/hourly?lat=40.7911106&lon=-73.8525824&forecastHours=5&key={Your_API_Key}
curl command example
curl 'https://api.tomtom.com/weatherforecast/v1/hourly?lat=40.7911106&lon=-73.8525824&forecastHours=5&key={Your_API_Key}'
Request parameters
Required parameters | Description |
---|---|
string | The base URL for calling the API. Value: |
string | Service version. Value: |
string | An API Key valid for the requested service. Value: Your valid |
double | Longitude. Value: between -180 and 180. |
double | Latitude. Value: between -90 and 90. |
Optional parameters | Description |
---|---|
integer | Number of hours from now for which the forecast is needed. Default value: |
Response data
Response body
The following JSON code block demonstrates a successful response from the API server.
1{2 "metadata": {3 "version": "1.0",4 "lastUpdatedTime": "2022-05-10T09:59:07.526391Z"5 },6 "data": {7 "stationCoordinates": {8 "lat": 52.45,9 "lon": 4.8310 },11 "hourlyWeatherInfo": [12 {13 "dateTime": "2022-05-10T09:00:00Z",14 "dateTimeLocal": "2022-05-10T11:00:00",15 "temperature": 19,16 "feelsLike": 19,17 "weatherCode": "D_OC_____",18 "windSpeed": 6.4,19 "windDirection": "SW",20 "sunProbability": 0,21 "precipitationProbability": 13,22 "thunderProbability": 0,23 "precipitation": 0.0,24 "pressure": 1016,25 "relativeHumidity": 64,26 "uvIndex": 227 }28 ]29 }30}
Response fields
The following table describes all of the response fields.
Primary fields | |
---|---|
Field | Description |
object | Metadata about the rendered response. |
object | Weather forecast information. |
object | Co-ordinates of the weather station where the weather data was recorded. |
array | Array of weather data, one per hour. |
metadata object | |
Field | Description |
string | Version of the data model. |
string (date-time) | UTC Timestamp of the response generated in ISO8601 format. |
stationCoordinates object | |
Field | Description |
double | Latitude of the weather station. |
double | Longitude of the weather station. |
hourlyWeatherInfo object | |
Field | Description |
string (data-time) | The time that applies to the forecast. |
string | The time that applies to the forecast in the local time zone. |
integer | The temperature in degrees celsius with a 1° precision. |
integer | Feels like temperature in degrees celsius with a 1° precision. |
string | Weather code. See the weatherCode values table for possible values. |
double | The expected wind speed in m/s. |
string | The expected direction of the wind, in up to three characters. |
integer | The probability of sunshine (value between 0 & 100 with a precision of 1). |
integer | The probability of getting some form of precipitation (value between 0 & 100 with a precision of 1). |
integer | The probability of having a thunderstorm (value between 0 & 100 with a precision of 1). |
integer | The total precipitation (in mm) with a precision of 0.1. |
integer | The barometric pressure (in hPa) with a precision of 1hPa. |
integer | The ambient relative humidity (value between 0 & 100 with a precision of 1). |
integer | The UV index. |
Response codes
Code | Meaning & possible causes |
| OK |
---|---|
| Unauthorized : The supplied API Key is not valid for this request (or missing). |
| Not Found : The specified path was not valid. At least one of the path parameters was omitted or not entered correctly. |
| Bad request : One of the supplied parameters has a wrong format. |
| Internal Server Error |
Examples
Get the weather forecast for the next 2 hours in Amsterdam Central station (lat: 52.37971857640887, lon: 4.900282722759855)
https://api.tomtom.com/weatherforecast/v1/hourly?lat=52.37971857640887&lon=4.900282722759855&forecastHours=2&key={Your_API_Key}
1{2 "metadata": {3 "version": "1.0",4 "lastUpdatedTime": "2022-05-12T09:01:09.154814Z"5 },6 "data": {7 "stationCoordinates": {8 "lat": 52.37,9 "lon": 4.910 },11 "hourlyWeatherInfo": [12 {13 "dateTime": "2022-05-12T08:00:00Z",14 "dateTimeLocal": "2022-05-12T10:00:00",15 "temperature": 15,16 "feelsLike": 15,17 "weatherCode": "D_CS_____",18 "windSpeed": 4.7,19 "windDirection": "W",20 "sunProbability": 95,21 "precipitationProbability": 2,22 "thunderProbability": 0,23 "precipitation": 0.0,24 "pressure": 1018,25 "relativeHumidity": 68,26 "uvIndex": 227 },28 {29 "dateTime": "2022-05-12T09:00:00Z",30 "dateTimeLocal": "2022-05-12T11:00:00",31 "temperature": 16,32 "feelsLike": 16,33 "weatherCode": "D_CS_____",34 "windSpeed": 5.2,35 "windDirection": "W",36 "sunProbability": 100,37 "precipitationProbability": 2,38 "thunderProbability": 0,39 "precipitation": 0.0,40 "pressure": 1018,41 "relativeHumidity": 59,42 "uvIndex": 343 }44 ]45 }46}
Request data for Daily Forecasts
HTTPS method: GET
- Constants and parameters enclosed in curly brackets must be replaced with their values.
- Please see the following Request parameters section with the required and optional parameters tables for their values. The generic request format is as follows.
URL format
https://{baseURL}/weatherforecast/{version}/daily?lat={latitude}&lon={longitude}&forecastHours={number_of_hours}&key={Your_API_Key}
Example
https://api.tomtom.com/weatherforecast/v1/daily?lat=40.7911106&lon=-73.8525824&forecastHours=5&key={Your_API_Key}
curl command example
curl 'https://api.tomtom.com/weatherforecast/v1/daily?lat=40.7911106&lon=-73.8525824&forecastHours=5&key={Your_API_Key}'
Required parameters | Description |
---|---|
string | The base URL for calling the API. Value: |
string | Service version. Value: |
string | An API Key valid for the requested service. Value: Your valid |
double | Longitude. Value: between -180 and 180. |
double | Latitude. Value: between -90 and 90. |
Optional parameters | Description |
---|---|
integer | Number of days from now for which the forecast is needed. Default: |
Response data
Response body
The following JSON code block demonstrates a successful response from the API server.
1{2 "metadata": {3 "version": "1.0",4 "lastUpdatedTime": "2022-07-28T09:00:06.318191Z"5 },6 "data": {7 "stationCoordinates": {8 "lat": 10.12,9 "lon": 9.8310 },11 "dailyWeatherInfo": [12 {13 "date": "2022-07-28",14 "minTemperature": 21,15 "maxTemperature": 28,16 "weatherCode": "D_OC_RAT2",17 "windSpeed": 1.4,18 "windDirection": "W",19 "sunProbability": 3,20 "precipitationProbability": 96,21 "thunderProbability": 57,22 "precipitation": 21.7,23 "uvIndex": 7,24 "sunRise": "06:09:00",25 "sunSet": "18:44:00",26 "moonRise": "05:48:00",27 "moonSet": "18:49:00",28 "moonPhase": 36029 }30 ]31 }32}
Response fields
The following table describes all of the response fields.
Primary fields | |
---|---|
Field | Description |
object | Metadata about the rendered response. |
object | Weather forecast information. |
object | Co-ordinates of the weather station where the weather data was recorded. |
array | Array of weather data, one per day. |
metadata object | |
Field | Description |
string | Version of the data model. |
string (date-time) | UTC Timestamp of the response generated in ISO8601 format. |
stationCoordinates object | |
Field | Description |
double | Latitude of the weather station. |
double | Longitude of the weather station. |
dailyWeatherInfo object | |
Field | Description |
string (data) | The day that applies to the forecast. |
string | The temperature in degrees celsius with a 1° precision. |
integer | The temperature in degrees celsius with a 1° precision. |
integer | Feels like temperature in degrees celsius with a 1° precision. |
string | Weather code. See the weatherCode values table for possible values. |
double | The expected wind speed in m/s. |
string | The expected direction of the wind, in up to three characters. |
integer | The probability of sunshine (value between 0 & 100 with a precision of 1). |
integer | The probability of getting some form of precipitation (value between 0 & 100 with a precision of 1). |
integer | The probability of having a thunderstorm (value between 0 & 100 with a precision of 1). |
integer | The total precipitation (in mm) with a precision of 0.1. |
integer | The UV index. |
integer | Time of the sunrise in local time. |
integer | Time of the sunset in local time. |
integer | Time of the moonrise in local time. |
integer | Time of the moonset in local time. |
integer | Moon phase in degrees between 0° and 360° with 1° precision. |
Response codes
Code | Meaning & possible causes |
---|---|
| OK |
| Unauthorized : The supplied API Key is not valid for this request (or missing). |
| Not Found : The specified path was not valid. At least one of the path parameters was omitted or not entered correctly. |
| Bad request : One of the supplied parameters has a wrong format. |
| Internal Server Error |
Examples
Get the weather forecast for the next 2 days for the Amsterdam Central station (lat: 52.37971857640887, lon: 4.900282722759855).
https://api.tomtom.com/weatherforecast/v1/daily?lat=52.37971857640887&lon=4.900282722759855&forecastHours=2&key={Your_API_Key}
1{2 "metadata": {3 "version": "1.0",4 "lastUpdatedTime": "2022-07-28T13:00:08.257660Z"5 },6 "data": {7 "stationCoordinates": {8 "lat": 52.37,9 "lon": 4.910 },11 "dailyWeatherInfo": [12 {13 "date": "2022-07-28",14 "minTemperature": 14,15 "maxTemperature": 22,16 "weatherCode": "D_CL_____",17 "windSpeed": 5.0,18 "windDirection": "E",19 "sunProbability": 18,20 "precipitationProbability": 6,21 "thunderProbability": 0,22 "precipitation": 0.3,23 "uvIndex": 5,24 "sunRise": "05:53:00",25 "sunSet": "21:39:00",26 "moonRise": "04:53:00",27 "moonSet": "22:11:00",28 "moonPhase": 36029 },30 {31 "date": "2022-07-29",32 "minTemperature": 14,33 "maxTemperature": 24,34 "weatherCode": "D_PC_____",35 "windSpeed": 4.4,36 "windDirection": "N",37 "sunProbability": 31,38 "precipitationProbability": 19,39 "thunderProbability": 0,40 "precipitation": 0.0,41 "uvIndex": 6,42 "sunRise": "05:55:00",43 "sunSet": "21:37:00",44 "moonRise": "06:04:00",45 "moonSet": "22:33:00",46 "moonPhase": 1047 }48 ]49 }50}
Weather codes
The weather codes are defined as a 9-character string with the following basic structure:
{T}_{XX}_{PPP}{L}
The single parts have the following meaning:
{T}
- single-letter time-of-day specifier: "D" or "N" for day and night respectively.{XX}
- 2-letter sky/cloud status specifier.{PPP}
- 3-letter precipitation type specifier.{L}
- 1-digit precipitation level specifier.
Valid code values
The following tables summarize the allowed values for the single parts and their interpretations:
Code | Time of day |
---|---|
| Day |
| Night |
Code | Sky/cloud status |
---|---|
| Clear sky |
| Mist |
| Fog |
| Sand/dust storm |
| Hazy |
| Some clouds |
| Partly cloudy |
| Cloudy |
| Overcast |
| Storm |
| Cyclone |
Code | Precipitation type |
---|---|
| Drizzle |
| Rain |
| Rain Showers |
| (Rain &) Thunderstorm |
| Snow |
| Snow showers |
| Snow & thunderstorm |
| Sleet |
| Sleet showers |
| Sleet & thunderstorm |
| Ice rain |
| Hail |
| Hail showers |
| Hail & thunderstorm |
Code | Precipitation level |
---|---|
| Light |
| Moderate |
| Heavy |
Combination Rules
- Both day and night codes can be combined with any other (valid) combination of the other parts.
- The cloud/sky status codes PC, CL, OC, ST, and CY can be combined with all precipitation codes. All other codes are followed by 5 underscores to fill up the entire code to 9 characters.
- If no precipitation is present, the weather code is also filled up with 5 underscores after the cloud/sky status.
- If precipitation is present, both type and level must be specified.
- All supported precipitation types can be combined with any valid value for the precipitation level.
Examples
The following codes are valid:
D_CS\_\_\_\_\_
- Day, clear sky - Berlin in summerD_OC_RAI2
- Day, overcast, moderate rain - Bielefeld in summerN_PC_RAT1
- Night, partly cloudy, light thunderstorm - the occasional summer thunderstormD_OC\_\_\_\_\_
- Day, overcast - lucky day for BielefeldD_CY_SNO3
- Day, cyclone, heavy snow - blizzardN_PC_SNO1
- Night, partly cloudy, light snow - white Christmas
The WindDirection enum
The WindDirection enum provides all possible values for the windDirection parameter of a _ WeatherInfo_. It defines 16 equally distributed compass directions plus one value for "variable" and one value for "unknown":
Value | Description |
---|---|
| Variable/changing wind directions. |
| Wind from the North. |
| Wind from the North-North-East. |
| Wind from the North-East. |
| Wind from the East-North-East. |
| Wind from the East. |
| Wind from the East-South-East. |
| Wind from the South-East. |
| Wind from the South-South-East. |
| Wind from the South. |
| Wind from the South-South-West. |
| Wind from the South-West. |
| Wind from the West-South-West. |
| Wind from the West. |
| Wind from the West-North-West. |
| Wind from the North-West. |
| Wind from the North-North-West. |
| Wind direction unknown. |