Error when send commands in smarthings server

Hello, I am trying to create a system to control my house. I need to control a Samsung TV.
When I try to request the url “https://api.smartthings.com/v1/devices/{deviceId}/commands” with correct authorization headers the error is the following:

[{“requestId”:"",“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”:}]}}]

The request body is the following:
{“commands”:[{“capability”:“switch”,“command”:“off”}]}

Headers are the following:

["Authorization: Bearer ",“Content-Type: application/json”,“accept: application/json”]

Can someone help me? Thank you.

Are you using POST method for this?
Have you tried including empty arguments array in the body?

Yes, I am using POST method.

If I use the following body the error is the same:
{“commands”:[{“component”:“main”,“capability”:“switch”,“command”:“off”,“arguments”:}]}

I was using python’s request library to send the POST request. Changing data=payload to json=payload fixed the problem for me. Corrected Code Below

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

activity_request = requests.post(‘https://api.smartthings.com/v1/devices/{deviceid}/commands’, json=payload, headers={‘Authorization’: 'Bearer ’ + custom_token})

1 Like

I solved the problem changing the body injection.

Now data are sent using GuzzleHttp php library that manage the body in a different way.

works for me, … thanks arjun