Count number of devices trough the API

Hi!

I like to count the number of devices based upon a filter via the API. Getting a list of devices is done like and works fine:

https://api.balena-cloud.com/v5/device?%24filter=is_online%20eq%20true&%24filter=is_on__commit%20eq%20'65dbac475a47007534da4774f367abb876f7819e'

According to the odata documentation, this is a possibility to do a count of items, with count or $count. I see the dashboard uses this too. However, I don’t have any luck en just get normal results.

https://api.balena-cloud.com/v5/device?%24count=true&%24filter=is_online%20eq%20true&%24filter=is_on__commit%20eq%20'65dbac475a47007534da4774f367abb876f7819e'

Is this possible with Balena API?

Hi, you can try this format to get the count:

https://api.balena-cloud.com/v5/device/$count?$filter=is_online%20eq%20true&$filter=is_on__commit%20eq%20%27bc1294cc67486ea2ca80b07353f96bba%27'

Here’s the unencoded query for easier reading:

https://api.balena-cloud.com/v5/device/$count?$filter=is_online eq true&$filter=is_on__commit eq 'bc1294cc67486ea2ca80b07353f96bba'

With https://api.balena-cloud.com/v5/device/$count I get a 400

"Malformed url: '/resin/device/%24count?%24filter=is_online%20eq%20true&%24filter=is_on__commit%20eq%20'65dbac475a47007534da4774f367abb876f7819e''"

Hey, I think there was an extra ' at the end of the query my colleague shared. It should read:

https://api.balena-cloud.com/v5/device/$count?$filter=is_online%20eq%20true&$filter=is_on__commit%20eq%20%27bc1294cc67486ea2ca80b07353f96bba%27