Queries the event records of a specified device.

Usage notes

You can query only the event records that are generated in the previous 30 days.

Note The storage period of an event record is calculated from the day when the record is generated.

QPS limits

Each Alibaba Cloud account can run up to 50 queries per second (QPS).

Note The RAM users of an Alibaba Cloud account share the quota of the Alibaba Cloud 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

ParameterTypeRequiredExampleDescription
ActionStringYesQueryDeviceEventData

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

EndTimeLongYes1516541900303

The end of the time range to query. The value is a 13-digit timestamp in milliseconds. Example: 1516541900303.

StartTimeLongYes1516541900303

The beginning of the time range to query. The value is a 13-digit timestamp in milliseconds. Example: 1516538300303.

Note You can query the event data only of the most recent 30 days.
IotInstanceIdStringNoiot_instc_pu****_c*-v64********

The ID of the instance. You can view the ID of the instance on the Overview page in the IoT Platform console.

Important
  • If your instance has an ID, you must specify this parameter. Otherwise, the call fails.
  • If the Overview page does not appear in the IoT Platform console or no ID is generated for your instance, you do not need to specify this parameter.

For more information, see Overview.

PageSizeIntegerNo10

The number of entries to return on each page. Valid values: 1 to 50. Default value: 10.

ProductKeyStringNoa1BwAGV****

The ProductKey of the product to which the device belongs.

Note If you specify this parameter, you must also specify the DeviceName parameter.
DeviceNameStringNolight

The DeviceName of the device.

Note If you specify a value for this parameter, you must also specify a value for the ProductKey parameter.
IdentifierStringNoPowerOff

The identifier of the event that you want to query. You can view the event identifier on the Define Feature tab of the Product Details page in the IoT Platform console. You can also call the QueryThingModel operation and view the event identifier in the returned TSL data.

Note If the PowerOff event belongs to a custom module named testFb, this parameter is set to testFb:PowerOff.

If you do not specify this parameter, the system queries all event data of the default module.

EventTypeStringNoinfo

The type of the event that you want to query. Valid values:

  • info: Information.
  • alert: Alert.
  • error: Error.
AscIntegerNo0

The order in which you want to sort the returned event records. Valid values:

  • 0: in reverse chronological order. This is the default value.
  • 1: in chronological order.
Note If you do not configure this parameter, the default value 0 is used. The system sorts the returned event records in reverse chronological order.
IotIdStringNoQ7uOhVRdZRRlDnTLv****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 a value for this parameter, you do not need to specify a value for the ProductKey or DeviceName parameter. The IotId parameter specifies a globally unique identifier (GUID) for the device. The value of the IotId parameter corresponds to a combination of the values of the ProductKey and DeviceName parameters. If you specify a value for the IotId parameter and values for the ProductKey and DeviceName parameters, the value of the IotId parameter takes precedence.

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

ParameterTypeExampleDescription
CodeStringiot.system.SystemException

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

DataStruct

The event records returned if the call succeeds.

ListArray of EventInfo

The array of events. Each element represents an event.

EventInfo
EventTypeStringinfo

The type of the event. Valid values:

  • info: information.
  • alert: alert.
  • error: error.
IdentifierStringPowerOff

The identifier of the event.

NameStringDevice shutdown

The name of the event.

OutputDataStringnull

The output parameter of the event. The value is a string in the MAP format.

TimeString1579163099000

The time when the event occurred. The value is a timestamp in milliseconds.

NextTimeLong1579163099000

The start time of the event records on the next page. The value is a timestamp in milliseconds.

  • If the Asc parameter is set to 0, you can specify this value for the EndTime parameter when you call this operation again to query the next page of event records.
  • If the Asc parameter is set to 1, you can specify this value for the StartTime parameter when you call this operation again to query the next page of event records.
NextValidBooleantrue

Indicates whether the next page exists.

  • true: The next page exists. The value of the NextTime parameter is returned. For more information, see the description of the NextTime parameter in this topic.
  • false: The next page does not exist.
ErrorMessageStringA system exception occurred.

The error message returned if the call fails.

RequestIdStringE55E50B7-40EE-4B6B-8BBE-D3ED55CCF565

The ID of the request.

SuccessBooleantrue

Indicates whether the call was successful.

  • true: The call was successful.
  • false: The call failed.

Examples

Sample requests

https://iot.cn-shanghai.aliyuncs.com/?Action=QueryDeviceEventData
&IotId=abcdef1234567************
&ProductKey=al**********
&DeviceName=device1
&EventType=info
&Identifier=lightLevel
&StartTime=1516538300303
&EndTime=1516541900303
&PageSize=10
&Asc=1
&<Common request parameters>

Sample success responses

XML format

<QueryDeviceEventDataResponse>
  <Data>
        <NextValid>false</NextValid>
        <NextTime>1579249151177</NextTime>
        <List>
              <EventInfo>
                    <Name>testEventInfoName</Name>
                    <Time>1516517974638</Time>
                    <OutputData>{"structArgs":{"structchildFLOATf71c20e":1.23,"structchildINT6b6b626":3,"structchildDATE663436a":"1516517966152","structchildDOUBLE08d0f74":1.23,"structchildTEXTdc764f9":"07b68264b0ba42c18e5f","structchildBOOLd260729":0,"structchildENUMbe62590":1},"enumArgs":0,"boolArgs":0,"floatArgs":2.3,"dateArgs":"1516517966152","intArgs":1,"doubleArgs":2.3,"textArgs":"dV56zbkzjBjw1Ti1dA52"}</OutputData>
                    <EventType>info</EventType>
                    <Identifier>testEventInfo</Identifier>
              </EventInfo>
        </List>
  </Data>
  <RequestId>45391E10-446B-4986-863E-1BA8CC44748F</RequestId>
  <Success>true</Success>
</QueryDeviceEventDataResponse>

JSON format

{
  "Data": {
    "NextValid": false, 
    "NextTime": 1579249151177, 
    "List": {
      "EventInfo": [
        {
          "Name": "testEventInfoName", 
          "Time": 1516517974638, 
          "OutputData": "{\"structArgs\":{\"structchildFLOATf71c20e\":1.23,\"structchildINT6b6b626\":3,\"structchildDATE663436a\":\"1516517966152\",\"structchildDOUBLE08d0f74\":1.23,\"structchildTEXTdc764f9\":\"07b68264b0ba42c18e5f\",\"structchildBOOLd260729\":0,\"structchildENUMbe62590\":1},\"enumArgs\":0,\"boolArgs\":0,\"floatArgs\":2.3,\"dateArgs\":\"1516517966152\",\"intArgs\":1,\"doubleArgs\":2.3,\"textArgs\":\"dV56zbkzjBjw1Ti1dA52\"}", 
          "EventType": "info", 
          "Identifier": "testEventInfo"
        }
      ]
    }
  }, 
  "RequestId": "45391E10-446B-4986-863E-1BA8CC44748F", 
  "Success": true
}

Error codes

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