Skip to content

Daily Weather Forecast

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.

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

complete weather request in python with all default values shown explicitly - note that the json is stored in the response variable, not printed directly, so formatting the json output is done locally by the json.dumps() function instead; 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.

 1import requests
 2import json
 3
 4url = "https://weather.magiclaneapis.com/v1/DailyWeather"
 5headers = {"Content-Type": "application/json", "Authorization": "YOUR_API_KEY_TOKEN" }
 6payload = {
 7   "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
 8   "noDays": 2
 9}
10response = requests.post(url, json=payload, headers=headers)
11r = response.json()
12print(json.dumps(r, indent=3))

This C example uses libcurl which can be installed on Linux (debian/ubuntu flavors), for example, like this:

sudo apt install libcurl4-gnutls-dev

Save the following code in a text file named weather.c using your favorite text editor, such as vi or geany, without the line numbers, those are only for reference:

complete weather request in C with all default values shown explicitly - 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.

 1#include <curl/curl.h>
 2
 3int main (int argc, char *argv[])
 4{
 5   CURL *curl;
 6   CURLcode res;
 7
 8   curl_global_init(CURL_GLOBAL_ALL);
 9   curl = curl_easy_init();
10   if (curl == NULL) { return 128; }
11
12   char* jsonObj = "{"
13      "\"coords\": \"43.0, 2.0; 42.6, 2.5; 42.3, 3.111\","
14      "\"noDays\": 2"
15   "}";
16   struct curl_slist *headers = NULL;
17   curl_slist_append(headers, "Content-Type: application/json");
18   curl_slist_append(headers, "Authorization: YOUR_API_KEY_TOKEN");
19
20   curl_easy_setopt(curl, CURLOPT_URL, "https://weather.magiclaneapis.com/v1/DailyWeather");
21   curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
22   curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
23   curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonObj);
24
25   res = curl_easy_perform(curl);
26
27   curl_easy_cleanup(curl);
28   curl_global_cleanup();
29   return res;
30}

Compile the program - for example, on Linux, at the terminal/command prompt type:

gcc weather.c -lcurl -o weather

A binary executable named weather is created which can be run like this to send the JSON POST request to the REST API endpoint, receive, and print the response:

./weather

To install D on Linux (debian/ubuntu flavors), at a terminal/command prompt type:

sudo apt install gdc

https://dlang.org/download.html
D can be downloaded for other platforms from this link

complete weather request in D with all default values shown explicitly - 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.

copy and paste this code in a text file named weather.d, without the line numbers - those are for reference:

 1import std.stdio;
 2import std.net.curl;
 3void main()
 4{
 5   string payload = '{
 6      "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
 7      "noDays": 2
 8   }';
 9   auto http = HTTP();
10   http.addRequestHeader("Content-Type", "application/json");
11   http.addRequestHeader("Authorization", "YOUR_API_KEY_TOKEN");
12   auto content = post("https://weather.magiclaneapis.com/v1/DailyWeather", payload, http);
13   writeln(content);
14}

Compile the program - for example, on Linux, at the terminal/command prompt type:

gdc weather.d -o weather

A binary executable named weather is created which can be run like this to send the JSON POST request to the REST API endpoint, receive, and print the response:

./weather

To install Julia on Linux (debian/ubuntu flavors), at a terminal/command prompt type:

sudo apt install julia

https://julialang.org/downloads/
Julia can be downloaded for other platforms from this link

To start Julia, type:

julia

To install the JSON and HTTP packages, at the Julia prompt type:

import Pkg; Pkg.add("JSON"); Pkg.add("HTTP")

complete weather request in Julia with all default values shown explicitly - 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.

copy and paste this code at the Julia prompt, without the line numbers - those are for reference:

 1using JSON, HTTP
 2req = """{
 3  "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
 4  "noDays": 2
 5  }"""
 6ans = HTTP.request("POST", "https://weather.magiclaneapis.com/v1/DailyWeather",
 7  ["Content-Type" => "application/json",
 8  "Authorization" => "YOUR_API_KEY_TOKEN"], req);
 9str = String(ans.body);
10print(str)
https://www.jetbrains.com/idea/download
The free IntelliJ IDEA Community Edition IDE can be downloaded from this link

Create a new kotlin project in IntelliJ.

In your new kotlin project, browse to src -> main -> kotlin -> Main.kt

Delete all the code in Main.kt and replace it with the kotlin weather request code shown below: (without the line numbers - those are only for reference)

complete weather request in kotlin with all default values shown explicitly - 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.

 1package kot.weather.post
 2
 3import java.net.URI
 4import java.net.http.HttpClient
 5import java.net.http.HttpRequest
 6import java.net.http.HttpResponse
 7
 8fun main()
 9{
10   val request: String = """
11   {
12      "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
13      "noDays": 2
14   }"""
15   print(request)
16   val client = HttpClient.newBuilder().build();
17   val postrequest = HttpRequest.newBuilder()
18   .uri(URI.create("https://weather.magiclaneapis.com/v1/DailyWeather"))
19   .header("Content-Type", "application/json")
20   .header("Authorization", "YOUR_API_KEY_TOKEN")
21   .POST(HttpRequest.BodyPublishers.ofString(request))
22   .build()
23   val response = client.send(postrequest, HttpResponse.BodyHandlers.ofString());
24   println(response.statusCode())
25   println(response.body())
26}
Click the green triangle play button to compile and run the kotlin weather request!
If there is a problem compiling because of a missing standard library, go in the menu to File->Project Structure and in the left panel select Modules and then in the right panel select the Dependencies tab and make sure the [x] KotlinJavaRuntime box is checked, then click Apply and OK, and run the example again.
https://www.jetbrains.com/idea/download
The free IntelliJ IDEA Community Edition IDE can be downloaded from this link

Create a new groovy project in IntelliJ.

In your new groovy project, browse to src -> Main.groovy

Delete all the code in Main.groovy and replace it with the groovy weather request code shown below: (without the line numbers - those are only for reference)

complete weather request in groovy with all default values shown explicitly - 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.

 1static void main(String[] args)
 2{
 3   def post = new URL("https://weather.magiclaneapis.com/v1/DailyWeather").openConnection();
 4   def message = '''
 5   {
 6      "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
 7      "noDays": 2
 8   }
 9   '''
10   post.setRequestMethod("POST")
11   post.setDoOutput(true)
12   post.setRequestProperty("Content-Type", "application/json")
13   post.setRequestProperty("Authorization", "YOUR_API_KEY_TOKEN")
14   post.getOutputStream().write(message.getBytes("UTF-8"));
15   def postRC = post.getResponseCode();
16   println(postRC);
17   if (postRC.equals(200)) {
18      println(post.getInputStream().getText());
19   }
20}
Click the green triangle play button to compile and run the groovy weather request!
https://www.jetbrains.com/idea/download
The free IntelliJ IDEA Community Edition IDE can be downloaded from this link

Create a new scala project in IntelliJ.

If Language: Scala is not listed in the create new project dialog, click on + to the right of the listed languages and select Scala to install the plugin, then restart intellij, create a new project and select Language: Scala.

In your new scala project, browse to the build.sbt file and add this line:

libraryDependencies += "org.scalaj" % "scalaj-http_2.13" % "2.4.2"

Note - at the time of this writing, the latest scala version is 2.13; the scalaVersion you see in build.sbt must match the scalaj-http_2.13 version; if the scalaVersion you see in build.sbt is newer than 2.13, such as 2.18 for example, then go to

https://mvnrepository.com/artifact/org.scalaj/scalaj-http

to see the latest scalaj-http_2.18 version, such as 2.5.6 for example, and replace 2.4.2 with that version, as well as scalaj-http_2.13 with scalaj-http_2.18

A notification button appears within the window to the right - Load sbt Changes - click this floating button to update.

In your new scala project, browse to src -> Main.scala

Delete all the code in Main.scala and replace it with the scala weather request code shown below: (without the line numbers - those are only for reference)

complete weather request in scala with all default values shown explicitly - 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.

 1import scalaj.http.{Http, HttpOptions}
 2object Main
 3{
 4   def main(args: Array[String]): Unit =
 5   {
 6      val request = s"""
 7      {
 8         "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
 9         "noDays": 2
10      }
11      """
12      val result = Http("https://weather.magiclaneapis.com/v1/DailyWeather")
13      .header("Content-Type", "application/json")
14      .header("Authorization", "YOUR_API_KEY_TOKEN")
15      .header("Accept-Encoding", "text")
16      .postData(request)
17      .option(HttpOptions.method("POST"))
18      .option(HttpOptions.readTimeout(10000)).asString
19      println(result)
20      println(result.code)
21   }
22}
Click the green triangle play button to compile and run the scala weather request!
The java code shown has to be saved in a text file named JSONPostReq.java and then compiled; at the commandline on either a Linux terminal or Windows command prompt type:
javac JSONPostReq.java
to compile the program making the json POST request to the Maps REST API, and then run it:
java JSONPostReq

complete weather request in java with all default values shown explicitly - 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.

 1import java.net.HttpURLConnection;
 2import java.net.URL;
 3import java.nio.charset.StandardCharsets;
 4import java.io.BufferedReader;
 5import java.io.InputStreamReader;
 6import java.io.OutputStream;
 7import java.io.IOException;
 8public class JSONPostReq
 9{
10   public static void main(String[] args) throws IOException
11   {
12      URL url = new URL("https://weather.magiclaneapis.com/v1/DailyWeather");
13      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
14      connection.setRequestMethod("POST");
15      connection.setDoOutput(true);
16      connection.setRequestProperty("Content-Type","application/json");
17      connection.setRequestProperty("Authorization","YOUR_API_KEY_TOKEN");
18      String payload = "{"
19         +"\"coords\": \"43.0, 2.0; 42.6, 2.5; 42.3, 3.111\","
20         +"\"noDays\": 2"
21         +"}";
22      byte[] out = payload.getBytes(StandardCharsets.UTF_8);
23      OutputStream stream = connection.getOutputStream();
24      stream.write(out);
25      int responseCode = connection.getResponseCode();
26      System.out.println("response code: "+responseCode);
27      if (responseCode == HttpURLConnection.HTTP_OK)
28      {
29         BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
30         String inputLine;
31         while ((inputLine = in.readLine()) != null)
32         {
33            System.out.println(inputLine.toString());
34         }
35         in.close();
36      }
37      connection.disconnect();
38   }
39}
The javascript code shown can be saved in a text file such as weather.js and run at the commandline using nodejs. In Linux, for example, if nodejs is not installed, it can be installed at the terminal commandline like this:
sudo apt install nodejs
also XMLHttpRequest needs to be installed:
npm install xhr2
Then weather.js can be run at the commandline like this:
nodejs weather.js

complete weather request in javascript with all default values shown explicitly - 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.

 1var XMLHttpRequest = require("xhr2");
 2const xhr = new XMLHttpRequest();
 3xhr.open("POST", "https://weather.magiclaneapis.com/v1/DailyWeather");
 4xhr.setRequestHeader("Content-Type","application/json");
 5xhr.setRequestHeader("Authorization","YOUR_API_KEY_TOKEN");
 6const body = JSON.stringify({
 7   "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
 8   "noDays": 2
 9});
10xhr.onload = () => {
11   console.log((xhr.responseText));
12};
13xhr.send(body);
The go code shown can be saved in a text file such as weather.go and run at the commandline using go. In Linux, for example, if go is not installed, it can be installed at the terminal commandline like this:
sudo apt install golang
Then weather.go can be run at the commandline like this:
go run weather.go

complete weather request in go with all default values shown explicitly - 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.

 1package main
 2import (
 3  "fmt"
 4  "bytes"
 5  "net/http"
 6  "io/ioutil"
 7)
 8
 9func main() {
10  reqUrl := "https://weather.magiclaneapis.com/v1/DailyWeather"
11  var data = []byte(`{
12    "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
13    "noDays": 2
14  }`)
15  req, _ := http.NewRequest("POST", reqUrl, bytes.NewBuffer(data))
16  req.Header.Add("Content-Type", "application/json")
17  req.Header.Add("Authorization", "YOUR_API_KEY_TOKEN")
18  res, _ := http.DefaultClient.Do(req)
19  defer res.Body.Close()
20  body, _ := ioutil.ReadAll(res.Body)
21  fmt.Println(res)
22  fmt.Println(string(body))
23}
https://dart.dev/get-dart Dart can be downloaded from here

To install dart on Linux (debian/ubuntu flavors), for example, it is best to download the .deb package from the Linux tab in the above link, such as dart_3.0.5-1_amd64.deb and install it like this:

sudo dpkg -i dart_3.0.5-1_amd64.deb

At a terminal/command prompt, type:

dart create myapp

to create a new dart application named myapp. A directory named myapp is created in the current directory, containing all necessary files. Go into this new directory:

cd myapp

User your favorite text editor, such as vim, geany or notepad to edit the pubspec.yaml file and add this dependency to the dependencies section as shown, then save it:

dependencies:
http: ^1.0.0

Next, edit the dart source code in lib/myapp.dart to look like this, without the line numbers - those are for reference only:

complete weather request in dart with all default values shown explicitly - 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.

 1import 'dart:io';
 2import 'dart:async';
 3import 'dart:convert';
 4import 'package:http/http.dart' as http;
 5
 6calculate() async
 7{
 8   try
 9   {
10      var sendString =
11      {
12          "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
13          "noDays": 2
14      };
15      final response = await http.post(
16         Uri.parse("https://weather.magiclaneapis.com/v1/DailyWeather"),
17         headers: {
18            "Content-Type": "application/json",
19            "Authorization": "YOUR_API_KEY_TOKEN"
20            //"Access-Control-Allow-Origin": "*"
21         },
22         body: jsonEncode(sendString)
23      );
24      print("${response.statusCode}");//2 equivalent ways to print output
25      //print("${response.body}");
26      //print(response.statusCode);
27      print(response.body);
28   }
29   catch(e)
30   {
31      print(e);
32   }
33}

You should replace the string “YOUR_API_KEY_TOKEN” with your actual API key token string. Now save the lib/myapp.dart file shown above, go to the myapp directory, and run it like this:

dart run

In Linux (debian/ubuntu flavors), for example, if perl is not installed, it can be installed at the terminal commandline like this:
sudo apt install perl
The JSON perl module can be installed like this:
sudo cpan JSON
complete weather request in perl with all default values shown explicitly -
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.
save this code in a text file named weather.pl (without the line numbers - those are for reference) and run it:
perl weather.pl
 1#! /usr/bin/env perl
 2use strict;
 3use warnings;
 4use LWP::UserAgent;
 5use HTTP::Request;
 6use JSON;
 7
 8my $url = 'https://weather.magiclaneapis.com/v1/DailyWeather';
 9my $json = '{
10      "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
11      "noDays": 2
12      }';
13my $req = HTTP::Request->new( 'POST', $url );
14$req->header( 'Content-Type' => 'application/json',
15'Authorization' => 'YOUR_API_KEY_TOKEN');
16$req->content( $json );
17my $ua = LWP::UserAgent->new;
18my $res = $ua->request( $req );
19print $res->decoded_content;
The php code shown can be saved in a text file such as weather.php and run at the commandline using php.
In Linux (debian/ubuntu flavors), for example, if php is not installed, it can be installed at the terminal commandline like this:
sudo apt install php php-curl
Then weather.php can be run at the commandline like this:
php weather.php

complete weather request in php with all default values shown explicitly - 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.

 1<?php
 2$mycurl = curl_init("https://weather.magiclaneapis.com/v1/DailyWeather");
 3if ($mycurl === false) {
 4   print "curl initialization FAILED\n";
 5}
 6$payload = array(
 7      "coords" => "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
 8      "noDays" => 2
 9      );
10$data_string = json_encode($payload);
11curl_setopt($mycurl, CURLOPT_CUSTOMREQUEST, "POST");
12curl_setopt($mycurl, CURLOPT_POSTFIELDS, $data_string);
13curl_setopt($mycurl, CURLOPT_RETURNTRANSFER, true);
14curl_setopt($mycurl, CURLOPT_FOLLOWLOCATION, true);
15curl_setopt($mycurl, CURLOPT_HTTPHEADER, array(
16   "Content-Type: application/json",
17   "Authorization: YOUR_API_KEY_TOKEN"
18   ));
19$result = curl_exec($mycurl);
20
21if ($result === false) {
22   print "POST request FAILED " . curl_error($mycurl) . " errno: " . curl_errno($mycurl) . "\n";
23}
24else { var_dump($result); }
25
26$httpReturnCode = curl_getinfo($mycurl, CURLINFO_HTTP_CODE);
27if ($httpReturnCode != "200") {
28   print "HTTP return code should be 200, got: " . $httpReturnCode . "\n";
29}
30if (is_resource($mycurl)) {
31   curl_close($mycurl);
32}
33?>
In Linux (debian/ubuntu flavors), for example, if R is not installed, it can be installed at the terminal commandline like this:
sudo apt install r-base-dev
Then start the R interpreter environment like this:
R
install the httr package within R like this:
install.packages("httr")
and answer y to the two installation-related questions that follow;

complete weather request in R with all default values shown explicitly - 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. note that the json is stored in the response variable, not printed directly, so formatting the json output is done locally by the toJSON() function: pretty = TRUE; (copy and paste the code into the R interpreter, without the line numbers - those are for reference)

1require(httr)
2require(jsonlite)
3body = '{
4     "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
5     "noDays": 2
6 }'
7result <- POST("https://weather.magiclaneapis.com/v1/DailyWeather", body = body,
8add_headers(.headers = c("Content-Type"="application/json", "Authorization"="YOUR_API_KEY_TOKEN")))
9toJSON(content(result), pretty = TRUE)

To exit the R environment, type q()

The ruby code shown can be saved in a text file such as weather.rb and run at the commandline using ruby. In Linux, for example, if ruby is not installed, it can be installed at the terminal commandline like this:
sudo apt install ruby
Then weather.rb can be run at the commandline like this:
ruby weather.rb

complete weather request in ruby with all default values shown explicitly - 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.

 1require "json"
 2require "uri"
 3require "net/http"
 4require "openssl"
 5
 6url = URI("https://weather.magiclaneapis.com/v1/DailyWeather")
 7http = Net::HTTP.new(url.host, url.port)
 8http.use_ssl = true
 9request = Net::HTTP::Post.new(url)
10request["Content-Type"] = "application/json"
11request["Accept-Encoding"] = "text"
12request["Authorization"] = "YOUR_API_KEY_TOKEN"
13request.body =
14{
15    "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
16    "noDays": 2
17}.to_json
18puts "sent"
19response = http.request(request)
20puts response.read_body

Save the following in a text file named Cargo.toml (case-sensitive). This contains the configuration and dependencies required for compilation.

 1[package]
 2name = "restpost"
 3version = "0.1.0"
 4edition = "2018"
 5
 6[[bin]]
 7name = "weather"
 8path = "weather.rs"
 9
10[dependencies]
11json = { version = "0.12.4" }
12reqwest = { version = "0.11.18", features = ["json", "blocking"] }
13serde_json = { version = "1.0.44" }
14tokio = { version = "1.28.2", features = ["macros", "full"] }

weather request with all default values shown explicitly; 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.

Save the following rust program in a text file named weather.rs

 1extern crate reqwest;
 2#[tokio::main]
 3async fn main() -> Result<(), reqwest::Error>
 4{
 5   let response = reqwest::Client::new()
 6   .post("https://weather.magiclaneapis.com/v1/DailyWeather")
 7   .header("Authorization", "YOUR_API_KEY_TOKEN")
 8   .header("Content-Type", "application/json")
 9   .header("Accept-Encoding", "text")
10   .json(&serde_json::json!({
11      "coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",
12      "noDays": 2
13      }))
14      .send().await?;
15   println!("{:?}",response.text().await?);
16   Ok(())
17}
In Linux (debian/ubuntu flavors), for example, if rust is not installed, it can be installed at the terminal commandline like this:
sudo apt install cargo rustc
Compile the program like this at the commandline, in the directory containing both Cargo.toml and weather.rs:
cargo b
To run the program, go to the build directory like this:
cd target/debug
and then run the weather program:
./weather
The Matlab code shown can be copied and pasted into Matlab, without the line numbers - those are for reference.

complete weather request in Matlab with all default values shown explicitly - 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.

 1method = matlab.net.http.RequestMethod.POST
 2f0 = matlab.net.http.HeaderField('Content-Type','application/json')
 3f1 = matlab.net.http.HeaderField('Authorization','')
 4header = [f0 f1]
 5str = [ ...
 6'{', ...
 7   + '"coords": "43.0, 2.0; 42.6, 2.5; 42.3, 3.111",', ...
 8   + '"noDays": 2,', ...
 9   + '}' ]
10request = matlab.net.http.RequestMessage( method, header, jsondecode(str) );
11response = request.send( 'https://weather.magiclaneapis.com/v1/DailyWeather' );
12jsonencode(response.Body.Data,"PrettyPrint",true)
The above code can also be saved in a text file named weather.m and run at the Matlab command prompt by typing weather and pressing enter. The current working directory shown at the top of the window should be set to the directory where weather.m was saved.
The scilab code shown can be copied and pasted into scilab, without the line numbers - those are for reference.
https://www.scilab.org/ Scilab can be downloaded from here

complete weather request in scilab with all default values shown explicitly - 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. note that the json is stored in the result variable, not printed directly, so formatting the json output is done locally by the toJSON() function, where 3 is the number of spaces to use for indentation (if this number is 0, then the json output is not indented/pretty printed)

1jsondata = ...
2"{" ...
3+"coords: 43.0, 2.0; 42.6, 2.5; 42.3, 3.111," ...
4+"noDays: 2," ...
5+"}"
6[result, status] = http_post("https://weather.magiclaneapis.com/v1/DailyWeather", toJSON(fromJSON(jsondata)), format="json", auth="YOUR_API_KEY_TOKEN" );
7toJSON(result,3)

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)

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

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

key

value

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

noDays

Number 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.

 1{
 2   "Daily forecast": [
 3      {
 4         "UpdateTime": 1699315200,
 5         "dailyWeatherParameters": [
 6            {
 7               "WeatherConditions": "Partly cloudy",
 8               "date": 1699315200,
 9               "parameters": {
10                  "TemperatureHigh": 14,
11                  "TemperatureLow": 5
12               }
13            },
14            {
15               "WeatherConditions": "Rain",
16               "date": 1699401600,
17               "parameters": {
18                  "TemperatureHigh": 15,
19                  "TemperatureLow": 6
20               }
21            }
22         ],
23         "latitude": 43,
24         "longitude": 2
25      },
26      {
27         "UpdateTime": 1699315200,
28         "dailyWeatherParameters": [
29            {
30               "WeatherConditions": "Mostly clear",
31               "date": 1699315200,
32               "parameters": {
33                  "TemperatureHigh": 13,
34                  "TemperatureLow": 5
35               }
36            },
37            {
38               "WeatherConditions": "Light rain",
39               "date": 1699401600,
40               "parameters": {
41                  "TemperatureHigh": 14,
42                  "TemperatureLow": 5
43               }
44            }
45         ],
46         "latitude": 42.599998474121094,
47         "longitude": 2.5
48      },
49      {
50         "UpdateTime": 1699315200,
51         "dailyWeatherParameters": [
52            {
53               "WeatherConditions": "Mostly clear",
54               "date": 1699315200,
55               "parameters": {
56                  "TemperatureHigh": 17,
57                  "TemperatureLow": 10
58               }
59            },
60            {
61               "WeatherConditions": "Mostly cloudy",
62               "date": 1699401600,
63               "parameters": {
64                  "TemperatureHigh": 17,
65                  "TemperatureLow": 9
66               }
67            }
68         ],
69         "latitude": 42.29999923706055,
70         "longitude": 3.1110000610351562
71      }
72   ],
73   "info": {
74      "copyrights": [
75         "MagicLane"
76      ]
77   },
78   "unit": "metric"
79}

Response body schema: application/json

key

value

Daily forecast

dailyWeatherParameters {

WeatherConditions

string

example: Clear

date

integer (uint64)

example: 1699027963

UNIX timestamp (seconds after 1 January 1970)

parameters {

TemperatureHigh

integer

example: 27

degrees Celsius

TemperatureLow

integer

example: 18

degrees Celsius

UpdateTime

integer (uint64)

example: 1699027963

UNIX timestamp

latitude

double (real number)

example: 27.36

longitude

double (real number)

example: 44.93