Page 1 of 1

Running into a CORS issue when trying to use the JSON API

Posted: Tuesday 09 June 2020 19:17
by Timmiej93
I'm trying to call some Domoticz API commands from a local webpage I'm running. Domoticz is running on a different Raspberry Pi, and thus has a different IP address. This is triggering CORS, which blocks my request. I've dealt with CORS before, but this time I simply can't get anything working, since I'm very confused about where I should be allowing this request. It feels like Domoticz itself is causing the CORS error, but that would be very weird for an API.

My setup:
Domoticz is running on RPi number 1.
Origin of request webpage is running on RPi number 2, with the webpage hosted on Apache.

Code: Select all

var xhttp = new XMLHttpRequest();
var url = "http://192.168.0.254:8080/json.htm?type=command&param=switchscene&idx=2&switchcmd=On";
xhttp.open("GET", url);
xhttp.setRequestHeader("Authorization", "Basic KEY");
xhttp.withCredentials = true;
xhttp.send();
So, is Domoticz blocking my request, or is Apache causing these CORS issues? I've tried setting the access control headers in apache, but they don't seem to do anything, which would make sense since the request is coming from that device, not going to it. Any help would be appreciated.

Re: Running into a CORS issue when trying to use the JSON API

Posted: Thursday 18 June 2020 19:49
by Timmiej93
Sadly not really fixed, but a workaround using Apache can be found here: https://www.domoticz.com/forum/viewtopi ... 11#p250711