Skip to main content

Get Health List

Description

The get_health_list function retrieves a list of health records for a specific device over a defined time range. It allows optional filtering and sorting of the results.

Function Signature:

def get_health_list(ws_config: WebServiceConfig, device_id: int, start_epoch: int, end_epoch: int, count: int = 0, order: str = 'desc') -> WebServiceResult:

Parameters

  • ws_config (WebServiceConfig): Configuration object for the web service.
  • device_id (int): The unique ID of the device whose health data is being queried.
  • start_epoch (int): The starting epoch time (in seconds) for the health data query.
  • end_epoch (int): The ending epoch time (in seconds) for the health data query.
  • count (int, optional): Maximum number of records to retrieve. If 0, retrieves all records in the specified time range.
  • order (str, optional): Sorting order of the results. Use 'desc' for newest first, or 'asc' for oldest first.

Returns

  • WebServiceResult: The result of the web service request, which includes:
    • http_response_code: The HTTP status code returned by the server.
    • http_response_string: The raw response body from the server.
    • json_data: The parsed JSON data containing the list of health records.

Example Usage

ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
device_id = 101
start_time = 1710000000
end_time = 1710086400

result = get_health_list(ws_config, device_id, start_time, end_time, count=10, order='asc')
print(result.json_data)

Behavior

  • Sends a POST request to the v1/devicehealth/list endpoint.
  • The request body includes filters like device ID, time range, result count, and order.
  • Returns a WebServiceResult that includes health records for the specified criteria if the call is successful.

Error Handling

  • General Exception: Any exceptions encountered during request preparation or execution are logged. The result's code is set to -1, and the description includes the exception message.