SOLVED Need assistance with "Execute Commands on a Device" POST SmartThings API

I am using Postman to try and work with the smartthings API on my network. For some reason, the https://api.smartthings.com/v1/devices/{deviceId}/commands

will not work no matter what. I can get other commands like “list devices” to work just fine, however whenever I try to properly send this one to list available commands for the device I receive this error

{
“requestId”: “61232A54-2134-436E-8BE1-FB6754C318B8”,
“error”: {
“code”: “ConstraintViolationError”,
“message”: “The request is malformed.”,
“details”: [
{
“code”: “BodyMalformedError”,
“target”: “httpRequestBody”,
“message”: “The request body is malformed and cannot be processed by server.”,
“details”:
}
]
}
}

PLEASE HELP I have tried to work on this for hours now and nothing will work :frowning:

A POST to that URL is for executing commands on the device not for listing them. The commands are defined by the capabilities of the device so you should already know what they are.

The API is expecting a JSON body defining the command you want to issue and either not getting one or getting one that doesn’t make sense.

1 Like

ok, this makes sense! thank you so much! how do I determine the syntax for device commands? this is a smart outlet, so they should be pretty simple.

Production Capabilities | SmartThings Developers I found this? I think this is the right direction?

running commands/switch/on does not work

running /commands/switchon does not work

running /commands/switchOn does not work

running commands/switch0 does not work

running /commands/switch/0 does not work

I am a beginner, this isn’t really making sense to me but I am trying my best

I FIGURED IT OUT!

I have absolutely no idea why this topic is so difficult to research but I got it working

the commands have to be in the “body” of the HTTP api request. postman or similar is essential for this.

here is the body code that I used

{
“commands”: [
{
“component”: “main”,
“capability”: “switch”,
“command”: “on”,
“arguments”:
}
]
}

if anyone sees this and knows of some good resources to learn about this type of HTTP manipulation that would be very helpful!

I just worked through this exact problem. I am however having trouble with my GoControl garage door controller. I get a response of 200 but nothing happens. Very weird and hard to trouble shoot since I’m sending all commands via Tasker.

The best way is to read the API documentation. The particular details in this case are at:

More generally though, I do recommend you read through the developer documentation and the API reference as it does help you get a better idea of how stuff fits together.

It was a bit easier when I started as there was less of a disconnect between end users and developers.

1 Like

Could you send a screenshot of how you formatted your body part? I’m getting the “malformed request” error. Thanks