Calls a specified service of a device.

Usage notes

When you define a service in a Thing Specification Language (TSL) model, the mode in which the service is called is specified. When you call a service by using this operation, IoT Platform uses a calling mode based on the Identifier parameter.

  • Synchronous mode: IoT Platform sends an RRPC request to a device and the device synchronously returns an RRPC response. For more information about how to implement an RRPC, see What is RRPC?
  • Asynchronous mode: IoT Platform sends a request to a device and the device asynchronously returns a response. For more information about topics, see Device properties, events, and services.

Limits

  • If you synchronously call a service, the timeout period is 5 seconds. If a server does not receive a response within 5 seconds, a timeout error occurs. No timeout limit is applied for asynchronous calls.
  • Each Alibaba Cloud account can run a maximum of 500 queries per second (QPS).
    Note 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 a 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 null

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 ID of the instance.

You do not need to specify this parameter.

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 DeviceName 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 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 is successful.

MessageId String abcabcabc1234****

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

Result String null

The result of the synchronous call.

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

ErrorMessage String A system exception 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 was successful.

  • true: The call was successful. However, this result does not indicate that the service is implemented. To obtain the implementation result, view the logs of the device.
  • 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.