Quantcast
Channel: Themen - Shelly Scripting - Shelly Forum
Viewing all articles
Browse latest Browse all 208

GET request to external REST API

$
0
0

For example you can try that


Shelly.call("http.get", {url: "https://www.api-couleur-tempo.fr/api/jourTempo/today",timeout: 1,ssl_ca: "*"}, RpcBackLectureTempoJourJ);



The json answer: {"dateJour": "2023-12-01","codeJour": 0,"periode": "2023-2024"}


The function to read json answer


function RpcBackLectureTempoJourJ(resultat, error_code, error_message, userdata)

{


if (error_code === 0) //--- pas d'erreur de lecture

{

if (resultat)

{

if (resultat.body !== undefined)

{

// print(resultat.body);

let json = JSON.parse(resultat.body);

if (json )

{

CodeCouleurJourJ = json.codeJour;

if (CodeCouleurJourJ===0) CouleurJourJ="Inconnu";

else if (CodeCouleurJourJ===1) CouleurJourJ="BLEU";

else if (CodeCouleurJourJ===2) CouleurJourJ="BLANC";

else if (CodeCouleurJourJ===3) CouleurJourJ="ROUGE";


}

}

}

}


}


everything works correctly


Viewing all articles
Browse latest Browse all 208