CallThingServices
Updated at:
Calls a device service.
Request syntax
POST /2020-04-30/things/ProductKey/DeviceName/services HTTP/1.1
Cookie: Cookie
PayloadImportant
2020-04-30 is the version number of the edge OpenAPI. This value cannot be changed.Request parameters
| Parameter Name | Type | Required | Description |
| ProductKey | String | Yes | The unique identifier for the product that the device belongs to. Obtain this identifier from the IoT Platform console. |
| DeviceName | String | Yes | The name of the device. Obtain the 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 call. The name and parameters must match the ones you set for the product's custom 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 | Type | Description |
| StatusCode | Number | The API return code. A value of 200 indicates success. Other values indicate failure. For more information, see Status codes. |
| Payload | JSON | The information returned from the service call. |
The response payload is in the following format.
{
"Data": {
"Services": [
{
"Name": "string",
"Returns": {
"Code": "string", // Error code that returned from the underlying call to the thing service.
"Message": "string", // Error message that returned from the underlying call services call.
"Data": string|boolean|number|array|object, // An optional data that returned from the underlying call services call.
}
}
],
"Timestamp": 1568262117344
}
}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?