Shelly - ajax api call return always error

264 Views Asked by At

I've developed a graphich interface for check all smart device in my home, but when I try to make a ajax call to shelly api for check the device status I get always error. If I utilize postman I able get the json result, but when make the same call in ajax not.

I use jquery 3.6.1 version and the authentication in my device is disabled.
The documentation is: https://shelly-api-docs.shelly.cloud/gen1/#shelly-motion-2

Can you help me?

The ajax call with postman:

enter image description here

This is my code:

function getMovementStatus(obj) {

    //http://192.168.68.103/status
    var url = protocol + '://' + obj.ip + '/status';
    
    
    
      var settings = {
        "url": url,
        "method": "GET",
        "timeout": 0,
        "contentType": 'application/json'
      };
    
    
      
      $.ajax(settings)
      .done(function (response) {
        console.log(response);
      })
      .fail(function (request, error) {
        console.log(error);
      });

}
1

There are 1 best solutions below

1
On

Where does the protocol field coming from? I don't see any declaration for the protocol field in the code. Add this line to your ajax function and try - var protocol = 'http'