Get Device Event Log

Last Updated on : 2024-01-30 09:30:31download

Get logs of events such as device online, offline, activation, and reset.

API address

GET: /v1.0/iot-03/devices/{device_id}/logs

Request parameter

Parameter nameTypeINRequiredDescription
device_idStringuritrueThe device ID.
event_typesStringquerytrueThe supported types of events in the logs. You can query multiple event types, separated with commas (,). This parameter value is required. Valid values:
  • 1: device online
  • 2: device offline
  • 3: device activation
  • 4: device reset
  • 6: firmware update
  • 8: device semaphore
  • 9: device restart
  • 10: timing
start_timeLongquerytrueThe 13-digit timestamp of the start time for a query.
end_timeLongquerytrueThe 13-digit timestamp of the end time for a query.
sizeIntegerqueryfalseThe number of logs to be queried. Default value: 20.
query_typeIntegerqueryfalseThe query type. Valid values:
  • 1: free edition. Default value is 1.
  • 2: paid edition.
last_row_keyStringqueryfalseThe last row key when you query logs by page. The value is from the last_row_key of the returned result. When the value is empty, it means to query the first page.

Return parameter

Parameter nameTypeDescription
resultDeviceLogResThe basic information by page.

Description of result

Parameter nameTypeDescription
last_row_keyStringThe identifier of the current page. It can be used as the last_row_key parameter value to query the next page.
device_idStringThe device ID.
has_moreBooleanSpecifies whether to return the next page.
listListThe list of data.

Description of list

Parameter nameTypeDescription
event_timeLongThe time when an event occurred.
event_fromStringThe source that triggers the specified event. Valid values:
  • 1: the device itself
  • 2: commands from the client
  • 3: third-party platform
  • 4: command from the cloud
  • -1: unknown
event_idIntegerThe event type. Valid values:
  • 1: device online
  • 2: device offline
  • 3: device activation
  • 4: device reset
  • 6: firmware update
  • 8: device semaphore
  • 9: device restart
  • 10: timing
event_valueStringThe event value.

Request example

GET: /v1.0/iot-03/devices/xxxxx/logs?last_row_key=xxx&event_types=1,2&start_time=1545898159931&end_time=1545898159935&size=20

Return example

{
    "result": {
        "last_row_key": "xxxxxxxxxxxxx",
        "device_id": "75500780ecfabc9a****",
        "has_next": true,
        "logs": [
            {
                "code": "switch_1",
                "event_from": "1",
                "event_id": 7,
                "value": "false",
                "event_time": 1560872567955
            }
        ]
    },
    "t": 1561344464370,
    "success": true
}

Error code

For more information, see error code.