# DeviceHistory API returns empty data

**URL:** <https://forums.balena.io/t/devicehistory-api-returns-empty-data/372198>\
**Category:** Product support\
**Tags:** support\
**Created:** [September 30, 2024, 2:16pm UTC](https://forums.balena.io/t/devicehistory-api-returns-empty-data/372198 "2024-09-30T14:16:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![toxa](https://avatars.discourse-cdn.com/v4/letter/t/ac91a4/32.png) [@toxa](https://forums.balena.io/u/toxa)\
**Post date:** [September 30, 2024, 2:16pm UTC](https://forums.balena.io/t/devicehistory-api-returns-empty-data/372198/1 "2024-09-30T14:16:44Z")

</div>

Hi,

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

> **[Balena Python SDK | balena](https://docs.balena.io/reference/sdk/python-sdk/#devicehistory)**

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:

```auto
#!/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)

```

---

<div class="post-metadata">

**Author:** ![mpous](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mpous/32/4742_2.png) [@mpous](https://forums.balena.io/u/mpous)\
**Post date:** [October 3, 2024, 11:14am UTC](https://forums.balena.io/t/devicehistory-api-returns-empty-data/372198/2 "2024-10-03T11:14:29Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![thgreasi](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/thgreasi/32/454_2.png) [@thgreasi](https://forums.balena.io/u/thgreasi)\
**Post date:** [October 8, 2024, 6:48am UTC](https://forums.balena.io/t/devicehistory-api-returns-empty-data/372198/4 "2024-10-08T06:48:47Z")

</div>

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?

```auto
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

---

<div class="post-metadata">

**Author:** ![toxa](https://avatars.discourse-cdn.com/v4/letter/t/ac91a4/32.png) [@toxa](https://forums.balena.io/u/toxa)\
**Post date:** [October 8, 2024, 1:04pm UTC](https://forums.balena.io/t/devicehistory-api-returns-empty-data/372198/5 "2024-10-08T13:04:10Z")

</div>

Hi!

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

---

<div class="post-metadata">

**Author:** ![joshbwlng](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/joshbwlng/32/10307_2.png) [@joshbwlng](https://forums.balena.io/u/joshbwlng)\
**Post date:** [October 10, 2024, 1:51am UTC](https://forums.balena.io/t/devicehistory-api-returns-empty-data/372198/6 "2024-10-10T01:51:15Z")

</div>

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.
