Skip to main content
Guides

Daily Weather Forecast

Estimated reading time: 22 minutes

In this guide you will learn how to get the daily weather forecast at a desired location, for a specified number of days.

Setup

First, get an API key token, see the Getting Started guide.

Daily Weather Forecast entry point

URL: https://weather.magiclaneapis.com/v1/DailyWeather

EXAMPLE

These are complete working examples in several different languages, showing how to use the weather REST API. You can try them right now.

Linux terminal / Windows command prompt:

curl "https://weather.magiclaneapis.com/v1/DailyWeather" -X POST -H "Content-Type: application/json" -H "Authorization: YOUR_API_KEY_TOKEN" -d @payload.json

Linux note - do not use @~/payload.json instead of @/home/user/payload.json because ~ does not resolve due to the @ ; use only relative path @payload.json or absolute path @/home/user/payload.json

where

payload.json is a text file containing the following:

complete payload.json file - coords , one or more semicolon ; separated latitude,longitude coordinate pairs - the weather will be returned for each one separately; noDays - Number of days for which to return the daily weather forecast.

{
"coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
"noDays": 2
}

In a linux terminal you can also send the request directly from the command line, without a file, like this: (this method does not work on windows)

curl "https://weather.magiclaneapis.com/v1/DailyWeather" -X POST -H "Content-Type: application/json" -H "Authorization: YOUR_API_KEY_TOKEN" -d \
'{
...
}'

The only difference is the added backslash after -d, and then the filename @/home/user/payload.json is replaced with the contents of the json file, starting with the next line - note that a single quote ‘ is added before the leading curly brace { and after the trailing curly brace } to enclose the file contents in single quotes - no backslashes are needed between the single quotes.

REQUEST PARAMETER DEFINITIONS

Request body schema: application/json

keyvalue
coords
(mandatory
parameter)
A list of ; (semicolon) separated latitude,longitude coordinate pairs - the weather will be returned for each separately. Example: “43,2; 42.6,2.5; 42.3,3.1”
Type: string
noDaysNumber of days for which to return the daily weather forecast.
Type: integer
Default value: 10 Maximum value: 10

RESPONSE

DailyWeather results

Each result item is given in a JSON block as shown below.

In the above examples, 3 coordinate pairs were requested, and 2 days of daily forecast, so the result shows 2 days of daily weather forecast for each of the 3 locations specified. The coordinates are latitude, longitude (degrees). The date timestamp field is the UNIX time in seconds since 1 January 1970 at 00:00.

{
"Daily forecast": [
{
"UpdateTime": 1699315200,
"dailyWeatherParameters": [
{
"WeatherConditions": "Partly cloudy",
"date": 1699315200,
"parameters": {
"TemperatureHigh": 14,
"TemperatureLow": 5
}
},
{
"WeatherConditions": "Rain",
"date": 1699401600,
"parameters": {
"TemperatureHigh": 15,
"TemperatureLow": 6
}
}
],
"latitude": 43,
"longitude": 2
},
{
"UpdateTime": 1699315200,
"dailyWeatherParameters": [
{
"WeatherConditions": "Mostly clear",
"date": 1699315200,
"parameters": {
"TemperatureHigh": 13,
"TemperatureLow": 5
}
},
{
"WeatherConditions": "Light rain",
"date": 1699401600,
"parameters": {
"TemperatureHigh": 14,
"TemperatureLow": 5
}
}
],
"latitude": 42.599998474121094,
"longitude": 2.5
},
{
"UpdateTime": 1699315200,
"dailyWeatherParameters": [
{
"WeatherConditions": "Mostly clear",
"date": 1699315200,
"parameters": {
"TemperatureHigh": 17,
"TemperatureLow": 10
}
},
{
"WeatherConditions": "Mostly cloudy",
"date": 1699401600,
"parameters": {
"TemperatureHigh": 17,
"TemperatureLow": 9
}
}
],
"latitude": 42.29999923706055,
"longitude": 3.1110000610351562
}
],
"info": {
"copyrights": [
"MagicLane"
]
},
"unit": "metric"
}