Bonjour à tous,
J’arrive à utiliser l’api http en javascript mais pas l’api jsonrpc car elle ne semble pas accessible directement en javascript à cause du CORS. Vous me confirmez que c’est bien le cas ou j’ai fais une erreur quelque part ?
Si c’est bien le cas, c’est dommage de devoir passer par un proxy node ou php pour ce problème de CORS.
//Fonctionne bien
fetch('https://xxx.eu.jeedom.link/core/api/jeeApi.php?apikey=xxx&type=cmd&id=30');
//Access to fetch at 'https://xxx.eu.jeedom.link/core/api/jeeApi.php' from origin 'https://xxx.fr' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
fetch('https://xxx.eu.jeedom.link/core/api/jeeApi.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"jsonrpc": "2.0",
"id": "1000",
"method": "cmd::execCmd",
"params": {"apikey": "xxx", "id": "30"}
})
});
Merci et bonne année
jerome