Using an API command in Node Red to toggle a switch

Hi
This is my first time at using the API to send a command.

I have successfully received the status of the switch (using bearer authorization)

GET
https://api.smartthings.com/v1/devices/{deviceId}/status
the status reply is:
payload.components.main.switch.switch.value.off

But my attempt at sending the command below fails and returns 406

PUT
https://api.smartthings.com/v1/devices/{deviceId}/commands.components.main.switch.switch.value. [off]

Postman status reply:
{
“components”: {
“main”:
“switch”: {
“switch”: {
“value”: “off”
}
}
}
}

Please could someone give me a pointer
Thanks in advance

Solution:

Here is the answer just in case anyone has the same question:

make a function node to feed a blank ‘http request’ node - but set to method “-setby msg.method-”

//function
var xxx = “off”;
msg.payload = {
“commands”: [{
“component”: “main”,
“capability”: “switch”,
“command”: xxx,
“arguments”: //<----open square bracket closed square bracket!!
}]
}
msg.headers = {}
msg.method = “POST”
msg.url = “https://api.smartthings.com/v1/devices/{{deviceid}}/commands”;
msg.headers[‘content-type’] = “application/json”
msg.headers[‘Authorization’] = “Bearer xxxxxxxxx-PAT-token-xxxxxxxxxxxx”
return msg;

1 Like