Balena Cloud API device filtering based on timestamp

Hi,
As there is at the moment no way to get hooked up through a webhook/notifications regarding new balena devices popping up, I went with the route in polling device date via the balena cloud api.
What I’m currently doing is something like this:

v6/device?$orderby=created_at asc&$filter=created_at gt datetime'2021-06-18T13:41:59.251Z'

What I’m essentially trying to do is to get latest created_at devices and saving it the newest created_at for another go and I’m expected to find newer devices after I use the latest created_at and showing either newer devices or no devices at all. Essentially I would expect to get no results if there are no new devices.

However the issue that I’m having is that by using the logical operator gt I would expect to find newer date, but what I’m ended having is seeing the latest device always (because it matches the same created_at as my latest device.

TL;DR: I think the gt is not working as expected, but working as a ge since I’m seeing the same data over and over again.

Thank you!

Hi, thank you for this report. I was able to confirm the behavior you reported when filtering devices using the created_at field. We will need to look into it more. For the mean time, I have created this open-balena-api issue for tracking: Device filter logical operators do not work as intended · Issue #697 · balena-io/open-balena-api · GitHub

Hello there,

I’d like to follow up your request. We have implemented the correction for this behaviour. Just a short excursion: Our database uses microsecond precision timestamps but we have millisecond precision timestamps in our API. Thus, comparisons on the create_at timestamp where failing.
Let us know, if you are still facing any unexpected behaviour and we will continue debugging.

Best Regards
Harald