Daily Forecasts

Learn how to get daily weather forecast information for a specific location.

Overview

The Forecast API allows us to get weather forecast information for a particular location. This API provides detailed weather information, including the temperature readings, air and pollen readings, wind speed, and rain probability during the day and at night.

Daily forecast endpoints

In this lesson, we learn how to retrieve the daily weather forecast data for a particular location for a single day and for a period of five days.

1 day of daily forecasts

To retrieve the daily weather forecast data for a single day for a given location, we make a GET request to the following URL:

http://dataservice.accuweather.com/forecasts/v1/daily/1day/{locationKey}

5 days of daily forecasts

For daily weather forecast data for the next five days of a particular location, we make a GET request to the following URL:

http://dataservice.accuweather.com/forecasts/v1/daily/5day/{locationKey}

Input parameters

The table below shows the list of input parameters for both endpoints.

Parameter

Type

Category

Description

API_KEY

string

required

This is our API key.

This is a query parameter.

locationKey

integer

required

This is the key of the location.

This is a path parameter.

language

string

optional

This is the language in which we have to return the results.

The default value is "en-us."

This is a query parameter.

details

boolean

optional

This is set to "True" to include full details in the response, otherwise it is set to "False." 

The default value is "False."

This is a query parameter.

metric

boolean

optional

This is set to "True" to display metric values in the response, otherwise it is set to "False."

The default value is "False."

This is a query parameter.

Sample code

In the code below, we enter 351409 on line 1 as the locationKey for Seattle, United States.

Note: Please refer to the appendix for a list of some well-known cities along with their location keys.

You can try adding some optional parameter(s) on lines 3–4 to fine-tune your results for 1-day forecasts. You can do the same for 5-day forecasts on lines 6–7.

Click the "Run" button to see the output.

Press + to interact
locationKey = 351409
url1Day = 'http://dataservice.accuweather.com/forecasts/v1/daily/1day/' \
+ str(locationKey) + '?apikey={{API_KEY}}'
url5Day = 'http://dataservice.accuweather.com/forecasts/v1/daily/5day/' \
+ str(locationKey) + '?apikey={{API_KEY}}'
res1Day = requests.get(url1Day)
res5Day = requests.get(url5Day)
printResponse(res1Day)
printResponse(res5Day)

The code above displays the forecast data for the specified location for a single day and five days. The output includes the response parameters specified in the table below, with some additional information. In case of failure, an appropriate error message is displayed.

Response parameters

Parameter

Type

Description

Headline

object

This is the most important weather description over the specified duration.

DailyForecasts.Day

object

This refers to the weather forecast information during the day.

DailyForecasts.Night

object

This refers to the weather forecast information during the night.

DailyForecasts.Temperature.Maximum

object

This tells us the maximum temperature.

DailyForecasts.Temperature.Minimum

object

This tells us the minimum temperature.

DailyForecasts.Link

string

This is the URL of AccuWeather's website for a detailed forecast.

DailyForecasts.MobileLink

string

This is the URL of AccuWeather's mobile site for a detailed forecast.

Note: The list of response parameters above is not exhaustive. Please refer to the appendix for details of the response.