CallThingServices
Updated at:
Copy as MD
Invokes a service for a device.
Request syntax
POST /2019-09-30/things/ProductKey/DeviceName/services HTTP/1.1
Cookie: Cookie
Payload
Request parameters
| Parameter | Type | Required | Description |
| ProductKey | String | Yes | The unique identifier of the product to which the device belongs. You can obtain this identifier from the IoT Platform console. |
| DeviceName | String | Yes | The name of the device. You can obtain this name from the IoT Platform console. |
| Cookie | String | Yes | The authentication cookie created by calling the CreateAuthCookie API. |
| Payload | JSON | Yes | The name and parameters of the service to invoke. These must match the service name and parameters that you set when you defined the product features in the IoT Platform console. For the format, see the request payload format below this table. |
The request payload is in the following format.
{
"Services": [
{
"Name": "string",
"Args": args // Optional arguments for the service.
}
]
}
Response syntax
HTTP/1.1 StatusCode
Content-Type: application/json
PayloadResponse parameters
| Parameter Name | Type | Description |
| StatusCode | Number | The status code returned for the request. A status code of 200 indicates that the request was successful. Other status codes indicate that the request failed. For more information about error codes, see Status codes. |
| Payload | JSON | The information returned from the service call. |
The response payload is in the following format.
{
"Code": 200,
"Message": "success|reason for failure",
"Data": {
"Services": [
{
"Name": "string",
"Returns": {
"Message": "success|reason for failure",
"Data": string|boolean|number|array|object, // Optional. The data returned from the underlying service call.
}
}
],
"Timestamp": 1568262117344
}
}
Complete example
$ curl -i -b token.cookie -d '{"Services":[{"Name":"setColor","Args": {"color":"red"}}]}' -k -X POST https://127.0.0.1:9999/2019-09-30/things/a1WabAEC***/N0hB9tiVWWZFMpALK***/services
HTTP/1.1 200 OK
Server: openresty/1.13.6.2
Date: Thu, 31 Oct 2019 11:17:47 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
{"Data":{"Services":[{"Name":"setColor","Returns":{"Message":"success","Data":[]}}],"Timestamp":1572520667899},"Code":200,"Message":"success"}
Is this page helpful?