Maker API access fails from outside private network

I'm accessing the Maker API from my local webserver (part of EventGhost) and it works well from anywhere on my local lan. However, when I access it from outside the network, my webpage loads fine but the API fails. The console log shows "TypeError: Failed to fetch" at the function that does a fetch.

function getdata(dev,val) { //read Hubitat via API
  const url = "http://192.168.1.137/apps/api/16/devices/?access_token=xxxxxxxxxxxxx";
  fetch(url)
    .then((response) => {
      return response.json();
    })
    .then((data) => {
      //process data here...;
    })
    .catch(function(error) {
      console.log(error);
    });
}

What could be causing this? Do I need to setup some special port forwarding in the router? Someone suggested that it may be a "CORS issue", but from what I've researched on that, it would be probably be way beyond my paygrade.

Well you won't be able to see it from the 192.168.1.137 as that is internal only. Due to NAT You need to use one of the external links. Look at your hubitat maker api instance, you will see cloud.hubitat.com/deviceid etc. That is what needs to be passed to the outside world. If you were passing it to an internal destination the above would work fine.

1 Like