Hi,
I am following SmartThings API doc: https://developer-preview.smartthings.com/api/public/#operation/executeDeviceCommands and I am trying to to send a POST request to my device. I have a token etc… and it works fine for switch but I can’t find a way to put arguments correctly for switchLevel. Maybe someone can share a working example?
Error response:
{
“requestId”: “389BF36E-CB1B-49E2-9CAF-9512A050115A”,
“error”: {
“code”: “ConstraintViolationError”,
“message”: “The request is malformed.”,
“details”: [
{
“code”: “UnprocessableEntityError”,
“target”: “[0].arguments.[0]”,
“message”: “invalid NUMBER type”,
“details”:
}
]
}
}
There is definitely something wrong with the arguments part but I can’t find a way to construct that JSON correctly. I don’t find any examples in the documentation that would show how to construct arguments.
I always get tied in a knot with the arguments. Given the error message, I’d suggest you probably don’t need the “level” key. Have you tried just "arguments": [ "integer": 40 ] ?
There’s already a request to provide more samples for the Rules API documentation and also, we have this Sample Rules repository where you can see the usage of other capabilities.
There seems to be a particular issue in the docs where payload samples are presented but can’t be expanded to see the content. It seems to particularly apply to the Devices endpoint.
No, the one I shared is used when we create a Rule that sends a command to the switchLevel capability.
For a direct command to the device through the API, the syntax shared by Graham is correct.
This is due to the Rules API grammar design. Rules are polymorphic and can accept many different payloads, hence, they go through a translation that parses the device commands.
Conversely, direct commands are specific to the device and don’t need a translation.
Another example is:
For devices that use the colorControl capability, the syntax for a direct command is the following: