Calls a specified service of a device.

Limits

  • If you synchronously call a service, the maximum timeout period is 5 seconds. If the server does not receive a response within 5 seconds, a timeout error occurs. If you asynchronously call a service, no timeout limit exists.
  • Each Alibaba Cloud account can run a maximum of 500 queries per second (QPS).
    Note Resource Access Management (RAM) users of an Alibaba Cloud account share the quota of the account.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes InvokeThingService

The operation that you want to perform. Set the value to InvokeThingService.

Args String Yes {"param1":1}

The input parameter of the service. The value is a JSON string. Example: Args={"param1": 1}.

If you do not need to specify this parameter, set the value to Args={}.

Identifier String Yes Set

The identifier of the service. To view the service identifier in the IoT Platform console, go to the Define Feature tab of the Product Details page. You can also call the QueryThingModel operation and view the service identifier in the returned TSL data.

Note If a service named testService belongs to a custom module named testFb, you can set this parameter to testFb:testService. The custom module is not the default module.
IotInstanceId String No iot_instc_pu****_c*-v64********

The instance ID. This parameter is not required for public instances. However, this parameter is required for Enterprise Edition instances.

IotId String No Q7uOhVRdZRRlDnTLv****00100

The ID of the device. The ID is a unique identifier that is issued by IoT Platform to the device.

Note If you specify this parameter, you do not need to specify the ProductKey or DeviceName parameter. The IotId parameter is a globally unique identifier (GUID), and corresponds to a combination of the ProductKey and DeviceName parameters.

If you specify the IotId parameter and a combination of the ProductKey and DeviceName parameters at the same time, the IotId parameter is used.

ProductKey String No a1BwAGV****

The ProductKey of the product to which the device belongs.

Note If you specify this parameter, you must also specify the DeviceName parameter.
DeviceName String No light

The name of the device to which the required service belongs.

Note If you specify this parameter, you must also specify the ProductKey parameter.

In addition to the preceding operation-specific request parameters, you must specify common request parameters when you call this API operation. For more information, see Common request parameters.

Response parameters

Parameter Type Example Description
Code String iot.system.SystemException

The error code returned if the call fails. For more information, see Error codes.

Data Struct

The data returned if the call succeeds.

MessageId String abcabcabc1234****

The ID of the message. IoT Platform sends the message to the device to call the service.

Result String {"param1":1}

The result of the synchronous call.

This parameter is not returned if you asynchronously call the service.

ErrorMessage String A system exception has occurred.

The error message returned if the call fails.

RequestId String E55E50B7-40EE-4B6B-8BBE-D3ED55CCF565

The ID of the request.

Success Boolean true

Indicates whether the call succeeds.

  • true: The call succeeded. However, this result does not indicate that the service is executed. The execution result is written in the device logs.
  • false: The call failed.

Examples

Sample requests

https://iot.cn-shanghai.aliyuncs.com/?Action=InvokeThingService
&ProductKey=a1BwAGV****
&DeviceName=device1
&Identifier=service1
&Args=%7B%22param1%22%3A1%7D
&<Common request parameters>

Sample success responses

XML format

<InvokeThingServiceResponse>
  <Data>
        <Result>{"code":200,"data":{},"id":"100686","message":"success","version":"1.0"}</Result>
        <MessageId>abcabc123</MessageId>
  </Data>
  <RequestId>A44C818E-FA7F-4765-B1E7-01D14AE01C6A</RequestId>
  <Success>true</Success>
</InvokeThingServiceResponse>

JSON format

{
  "Data": {
    "Result": "{\"code\":200,\"data\":{},\"id\":\"100686\",\"message\":\"success\",\"version\":\"1.0\"}", 
    "MessageId": "abcabc123"
  }, 
  "RequestId": "A44C818E-FA7F-4765-B1E7-01D14AE01C6A", 
  "Success": true
}

Error codes

For a list of error codes, visit the API Error Center.