/api/devices doesn't return a list with the same order
Seluj78 opened this issue · 7 comments
Description
Using the endpoint GET /api/devices
, I expect to get a list of devices that are always the same order.
With 3 devices, running my script that calls /api/devices?per_page=100
returns the list sorted seemingly randomly. It might be the same for a few runs then change again.
Edition
Community
Version
0.14.1
Hi, @Seluj78
You can use sort_by and order_by to enforce a sort order. For example, with /api/devices?per_page=100&order_by=desc&sort_by=last_seen
, it will return the list of devices with the most recently seen devices first.
In any case, I'm trying to reproduce this. Could you please tell me, if you know, how many requests you need to make to get a randomly sorted list?
Taking a look at the function that retrieves the list of devices, if no sorting or ordering options are specified, the query defaults to using the last_seen
field for sorting. Consequently, when connecting to a different device, it will appear at the top of the list. The code is available here.
Sorting by name is already possible, and this is the original example of the documentation. So, /api/devices?per_page=100&order_by=[asc|desc]&sort_by=name
should work in your case.
Alright thanks. I was just wondering if this was a bug.
In my opinion, it should be sorted by name by default so that the list of devices, when retrieved programmatically doesn't change from call to call (unless renamed) or maybe sorted by ID. In any case, I'll let you close the issue if you don't think it's necessary
This behavior is a result of our UI listing devices based on the last_seen attribute. To simplify matters, we have incorporated this as the default.
We appreciate your opinion and will take it into consideration for future developments. Thank you for providing your input.
We plan to modify the default device list order for API v2. However, to ensure compatibility for existing users, we are maintaining the current behavior.
We plan to modify the default device list order for API v2. However, to ensure compatibility for existing users, we are maintaining the current behavior.
Great ! Thank you