Use this operation to query service records of a specified device.

Limits

You can query service data that was generated within the last 30 days.

Note The data of a service is stored from the day the service data was generated. Data that was generated more than 30 days ago is no longer stored.

Request Parameters

Parameter Type Required Description
Action String Yes The operation that you want to perform. Set the value to QueryDeviceServiceData.
IotId String No

The identifier of the device whose service records you want to query.

Note If you use this parameter, ProductKey and DeviceName are not required. IotId is a globally unique identifier (GUID) of a device, and corresponds to a combination of ProductKey and DeviceName. If you specify both IotId and the combination of ProductKey and DeviceName, the system follows IotId.
ProductKey String No

The product key of the device whose service records you want to query.

Note If you use this parameter, DeviceName is required.
DeviceName String No

The name of the device whose service records you want to query.

Note If you use this parameter, ProductKey is required.
Identifier String Yes The identifier of the service. You can view the Identifier values of services in the TSL of the product on the Define Feature page in the IoT Platform console.
StartTime Long Yes The start time of service records that you want to query. The value is a 13 digit timestamp.
EndTime Long Yes The end time of service records that you want to query. The value is a 13 digit timestamp.
PageSize Integer No The number of records per page in the response. The maximum limit is 50.
Asc Integer No

The sorting order of service records in returned results. Value options:

  • 0: In reverse chronological order.

  • 1: In chronological order.

The default value is 1.

Common Request Parameters - Yes See Common parameters.

Response parameters

Parameter Type Description
RequestId String The globally unique ID generated by Alibaba Cloud for the request.
Success Boolean Indicates whether the call is successful. A value of true indicates that the call is successful. A value of false indicates that the call has failed.
ErrorMessage String The error message returned when the call fails.
Code String The error code returned when the call fails. For more information about error codes, see Error codes.
Data Data The device service records returned when the call is successful. See the following table Data.
Table 1. Data
Parameter Type Description
List List<ServiceInfo> The collection of service records. Each ServiceInfo represents a service record. For elements in a ServiceInfo, see ServiceInfo.
NextValid Boolean Indicates whether there is a next page of records. A value of true indicates there is a next page, and a value of false indicates there is not a next page.
NextTime Long The start time of service record on the next page.
Table 2. ServiceInfo
Parameter Type Description
Name String The service name.
Time Long The time when the service was executed.
OutputData String The output parameters of the service in key:value pattern.
InputData String The input parameters of the service in key:value pattern.
Identifier String The identifier of the service.

Examples

Request example

https://iot.cn-shanghai.aliyuncs.com/?Action=QueryDeviceServiceData
&IotId=SR8FiTu1R9tlUR2V1bmi0010*****
&ProductKey=al**********
&DeviceName=device1
&Identifier=set
&StartTime=1516538300303L
&EndTime=1516541900303L
&PageSize=10
&Asc=1
&<Public Request Parameters>

Response parameter

  • JSON format

    {
      "RequestId":"57b144cf-09fc-4916-a272-a62902d5b207",
      "Success": true,
      "Data": {
        "NextValid": true,
        "NextTime": 1517315865197,
        "List": {
          "ServiceInfo": [
            {
              "Name": "set",
              "Time": 1517315865198,
              "OutputData": "{\"code\":200,\"data\":{},\"id\":\"100686\",\"message\":\"success\",\"version\":\"1.0\"}",
              "InputData": "{\"LightAdjustLevel\":123}",
              "Identifier": "set"
            }
          ]
        }
      }
    }
  • XML format

    <? xml version='1.0' encoding='utf-8'? >
    <QueryDeviceServiceDataResponse>
        <RequestId>57b144cf-09fc-4916-a272-a62902d5b207</RequestId>
        <Success>true</Success>
        <Data>
            <NextValid>true</NextValid>
            <NextTime>1517315865197</NextTime>
            <List>
                <ServiceInfo>
                    <Name>set</Name>
                    <Time>1517315865198</Time>
                    <OutputData>{"code":200,"data":{},"id":"100686","message":"success","version":"1.0"}</OutputData>
                    <InputData>{"LightAdjustLevel":123}</InputData>
                    <Identifier>set</Identifier>
                </ServiceInfo>
            </List>
        </Data>
    </QueryDeviceServiceDataResponse>