TR50 Message Format
To use the API command interface, you must format the messages you send according to the TR50 protocol specification, which defines a JSON object format that can be processed by numerous applications.
Request
The params object is optional, and the contents depend on the particular command. If a command has no parameters, do not send the params object.
You can send multiple commands in a single packet. Each command must have a unique command ID to enable Device Cloud to correlate the replies. In the following example, the values 1 and 2 are command IDs.
The auth object is only required when using HTTP. If you are using MQTT, then your session information is already associated with your MQTT session and does not need to be included.
{
"auth" : {
"sessionId" : "sessionId"
},
"1" : {
"command" : "command1",
"params" : {
command1Param
}
},
"2" : {
"command" : "command2",
"params" : {
command2Param1,
command2Param2
}
}
}
Reply
Each response contains a success Boolean key. If the value of success is false, the reply contains the errorCodes and errorMessages arrays that provide one or more error codes with information about the request failure. The response format is the same for HTTP and MQTT requests.
{
"1" : {
"success" : true
},
"2" : {
"success" : false,
"errorCodes" : [-22],
"errorMessages" : ["Device not found"]
}
}