Skip to main content
Guides

Current Weather

Estimated reading time: 23 minutes

In this guide you will learn how to get the current weather at a desired location.

Setup

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

Current Weather entry point

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

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/CurrentWeather" -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; details - 0 returns weather description and temperature (default), 1 - returns all available weather parameters.

{
"coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
"details": 0
}

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/CurrentWeather" -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
detailsType: integer
Default value: 0
Possible values - 0:returns weather description and temperature; 1:returns all available weather parameters

RESPONSE

CurrentWeather results

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

In the above examples, 3 coordinate pairs were requested, so the result shows the weather 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. Sunrise and Sunset times are also in UNIX time, as is the (most recent) UpdateTime .

If details is set to 0, then the parameters block contains only Sunrise , Sunset , and Temperature ; otherwise, if details is set to 1, this block contains all parameters as shown below.

{
"CurrentWeather": [
{
"CurrentParameters": {
"WeatherConditions": "Mostly clear",
"date": 1699354819,
"daylight": "day",
"parameters": {
"DewPoint": 2,
"FeelsLike": 13,
"Humidity": 53,
"Pressure": 1020,
"Sunrise": 1699338818,
"Sunset": 1699375028,
"Temperature": 13,
"UV": 1,
"Visibility": 24.14,
"WindDirection": 0,
"WindSpeed": 0
}
},
"UpdateTime": 1699354200,
"latitude": 43,
"longitude": 2
},
{
"CurrentParameters": {
"WeatherConditions": "Mostly clear",
"date": 1699354820,
"daylight": "day",
"parameters": {
"AirQuality": 4,
"DewPoint": 2,
"FeelsLike": 11,
"Humidity": 55,
"Pressure": 1020,
"Sunrise": 1699338646,
"Sunset": 1699374960,
"Temperature": 12,
"UV": 1,
"Visibility": 24.14,
"WindDirection": 0,
"WindSpeed": 1
}
},
"UpdateTime": 1699354200,
"latitude": 42.599998474121094,
"longitude": 2.5
},
{
"CurrentParameters": {
"WeatherConditions": "Rain showers",
"date": 1699354820,
"daylight": "day",
"parameters": {
"DewPoint": 7,
"FeelsLike": 16,
"Humidity": 56,
"Pressure": 1020,
"Sunrise": 1699338461,
"Sunset": 1699374852,
"Temperature": 16,
"UV": 1,
"Visibility": 24.07,
"WindDirection": 31,
"WindSpeed": 6
}
},
"UpdateTime": 1699354200,
"latitude": 42.29999923706055,
"longitude": 3.1110000610351562
}
],
"info": {
"copyrights": [
"MagicLane"
]
},
"unit": "metric"
}