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

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
Timmiej93
Posts: 64
Joined: Saturday 26 December 2015 0:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
Timmiej93
Posts: 64
Joined: Saturday 26 December 2015 0:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by Timmiej93 »

Sadly not really fixed, but a workaround using Apache can be found here: https://www.domoticz.com/forum/viewtopi ... 11#p250711
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], palnic and 1 guest