Sending request with scriptable app to Shelly cloud

966 Views Asked by At

After connecting and wiring the Shelly2.5 with my shutter, trying to connect it with Siri. Decided to do this with Scriptable app and then connect Siri commands to it, so it will run.

Currently have an issue to send the request from the Scriptable app as the code is written below, when i tried to fire it from Postman it works.


// # open shutter

let url = "https://domain.shelly.cloud";
let suffix ="/device/relay/roller/control/";
let auth_key = "AAAABBBBCCCDDDEEEEFFFFFF____EXAMPLE_TOKEN___AAAABBBBCCCDDDEEEEFFFFFF";

let channel = 0;
let turn = "on";

let direction = "open";
let id = "C45bbe75f1bd";


let body = { 
  "auth_key":auth_key, 
  "id": id, 
  "direction":direction
  };
// console.log(body);
let req = new Request(url + suffix); 
// console.log(url+suffix);
req.method = "POST";
req.body = body;

req.headers = { "Content-Type":"application/x-www-form-urlencoded" };


// req.body = JSON.stringify(body)
let json = await req.loadJSON()
console.log(json);

the current response:

2021-09-13 11:20:46: {"isok":false,"errors":{"invalid_header":"Unauthorized! Wrong authorization header provided!","invalid_token":"The login information is invalid! Please login again!"}}

please notice that i change the real token and the real sub domain for shelly cloud. It will be grate if someone know how to fix this, Thanks

1

There are 1 best solutions below

0
On

looks like the Shelly expect form-encoded body. Try this

let form  = Object.keys(body).map( k => `${k}=${encodeURIComponent(body[k])}`).join('&')

req.body = form