I am totally a noob to coding and have no background in programming, hence have tried my best to understand things but am unable to.
I am trying to get use an android app (HTTP Shortcut) to do a POST to a googleappscript, which will make the switchbot bot do a press. Basically this app is simply to get the script running.
However, trying various methods with doPost and doGet, I still have no idea how to integrate it or where to put it into the code below.
function main() {
var headers = {
"Authorization" : "SWITCHBOT_TOKEN_KEY",
"Content-type": "application/json; charset=utf-8"
};
var data = {
"command": "press",
"parameter": "default",
"commandType": "command"
};
var options = {
'method' : 'post',
"headers" : headers,
muteHttpExceptions: true,
"payload" : JSON.stringify(data)
};
var deviceid = "INSERT_SWITCHBOT_DEVICEID";
var url1 = https://api.switch-bot.com/v1.0/devices/${deviceid}/commands
;
var response = UrlFetchApp.fetch(url1,options);
var json=JSON.parse(response.getContentText());
console.log(json)
}
Any assistance with this would be great!