DeviceHistory API returns empty data

Hi,

I’m trying to get Device History, by trying a few examples provided in the reference

But the API returns empty data.
Is it some kind of a feature that needs to be enabled before it starts working? Or, perhaps, I’m missing something.
Here is my sample code:

#!/usr/bin/env python3
from balena import Balena
import datetime
import os

balena = Balena()
token=open(os.path.expanduser('~/.balena/token'),'rt').read()
balena.auth.login_with_token(token)
print(balena.auth.get_actor_id())

for app in balena.models.application.get_all():
    print(app['app_name'], app['id'])
    history = balena.models.device.history.get_all_by_application(app['id'], from_date=datetime.datetime.now() + datetime.timedelta(days=-100), to_date=datetime.datetime.now())
    print(history)

Hello @toxa first of all welcome to the balena community!

Let me ask internally to the team and we will keep you posted!

Feel free to share more tests that you do here!

Hi,
I was able to use your code snippet using the latest version of the python balena-sdk and I was able to bet results back without issues.
Can you try the following curl so that we can get a hint on whether this is an API or SDK issue?

curl 'https://api.balena-cloud.com/v6/device_history?$filter=(created_at%20ge%20datetime%272024-03-01T00:00:00.000Z%27)%20and%20(belongs_to__application%20eq%20<APPLICATION_ID>)' \
  -H 'authorization: Bearer <TOKEN>'

I would also suggest you to first provision a new device on that fleet, so that there are recent device_history records available for sure.

Kind regards,
Thodoris

Hi!

There was a release pushed recently to the device I’m interested in,
but the curl returns:
{"d":[]}

Hi, I tested both the curl and your script using an application I know to have recent device history and got the expected populated response from both. Is it possible that a release was created for your application, but the device is pinned and therefore wasn’t updated to use the new release? Perhaps try updating the device’s release via the dashboard and try querying device history again.