Hi,
Yes thats the correct address for the webhook.
I’ve found a further problem that webcore can not handle some non standard char actors, so I’ve updated the script to remove these. There’s also commented out code to remove some JSON items you may not be interested in, however they do not cause any problems. (I tried these when I thought there may be an issue with the length of the message)
The script works fine for all operations, including play. When you put in the details of your piston in the path variable, ensure you format as the redacted example (start with /api and include everything upto & including the final :
var http = require(‘http’);
var https = require(‘https’);
http.createServer(function(req, res){
main(req,res);
}).listen(1111);
function main(req, res){
let data = ;
req.on(‘data’, (chunk) => {
data.push(chunk);
});
req.on('end', () => {
data = Buffer.concat(data).toString();
// at this point, `data` has the entire request body stored in it as a string
console.log(' ');
console.log(' ');
console.log('Processing request');
header = data.substr(26,43);
header = "--------------------";
data = data.substr(data.indexOf("name="));
data = data.substring(50,data.indexOf(header));
var data2 = '{"payload":' + data + '}';
console.log(data2);
var jsondata2 = JSON.parse(data2);
// remove unwanted JSON items
// delete jsondata2.payload.Metadata[‘Role’];
// delete jsondata2.payload.Metadata[‘Similar’];
// delete jsondata2.payload.Metadata[‘Location’];
// delete jsondata2.payload.Metadata[‘summary’];
data2 = JSON.stringify(jsondata2);
data2 = data2.replace(/[^\x20-\x7E]/g, ‘’); // Remove non printable chars
console.log(‘tidied data’);
console.log(data2);
const options = {
hostname: ‘graph-eu01-euwest1.api.smartthings.com’,
path: ‘/api/token/**********:’,
method: ‘GET’,
headers: {
‘Content-Type’: ‘application/json’,
‘Content-Length’: data2.length
}
}
//make request
const req2 = https.request(options, res2 => {
console.log(statusCode: ${res2.statusCode})
res2.on('data', d => {
process.stdout.write(d)
})
})
req2.on('error', error => {
console.error(error)
})
req2.write(data2)
req2.end()
});
res.end();
}