Nov 03, 2021 07:08 AM
How are records ordered in a GET request when no view or sortby parameters are entered. I dont understand the order of the default response.
Nov 03, 2021 09:28 AM
Unfortunately it’s a random order, so if you want them in a certain order, you will need to specify it yourself.
(I haven’t tested this, but I believe that the order is actually an alphabetical listing by Record ID, which is completely random.)
Nov 03, 2021 09:54 AM
No Problem Thank you for clarifying I figured as much after testing but wasnt certain. Suppose this can be closed now.
Nov 03, 2021 10:42 AM
@kuovonne I don’t deal in the REST API, but my understanding is that the order records are retrieved is typically by creation date. Do you happen to know if that’s the case?
Nov 03, 2021 12:07 PM
I do not know the default sort order, and it is not documented. In any case, the default sort order is not the same as any order that is seen in the user interface (except by chance).
If you need records in a particular order, especially if you need 100 or fewer records, I highly recommend specifying a sort order.
Nov 03, 2021 12:17 PM
Yeah, this is very bizarre — my assumption above about it sorting by Record ID was wrong. And yet it also doesn’t sort by Creation Date, either.
I just tested this on a very small sample of 5 records, and this is the order of Record ID’s that it returned:
rec2tZeyhfWhK5YT2
recnGShmnP4HUCVVy
recEaCKguCzhBtCYh
recsJukjkzONmEKqE
recLea8Kg9UkSLHsQ
And this is the order of creation dates that it returned:
2020-06-20T14:06:16.000Z
2020-12-17T20:05:53.000Z
2020-12-17T20:05:11.000Z
2020-12-17T20:06:01.000Z
2021-01-15T00:22:43.000Z
So it looks like it’s almost in alphabetical Record ID order (but it’s not), and it looks like it’s almost in creation date order (but it’s not).
So I think that the ordering must be truly random? We may want to reach out to Airtable Support to see if they know the answer to this, although the easy solution is to always specify our own sort order.
I’m not sure if @Adam_Minich is actively visiting the forums, but I’m going to tag him here to see if he has any insights on this.
Nov 03, 2021 01:26 PM
I doubt that the order is truly random. Plus, if the end user actually needs a random record, I would not rely on the sort order being random. I also would not rely on the sort order being either the same or different across different calls. I prefer to think of the sort order as something more vague such as “indeterminate” or “unspecified”.
Nov 03, 2021 07:19 PM
I think Scott is probably right. I just ran 10 tests with 7 records; each test used the same table but the data was entered the same after deleting the records. Random outcomes with every API request. This doesn’t mean they are reliably randomized but it does suggest if there is a pattern it is likely related to Airtable’s s storage layer and nothing specifically in the fields.
To be clear, with such a small sample size, we could predict some requests may return similar or identical orders. However, the law of large numbers tells us this would not be the case in most data sets. After further contemplation, my hunch is there is a pattern but it is likely related to how data at rest is actually recalled - perhaps a performance optimized algorithm deep inside Airtable.
I think we need a sandwich bet. :winking_face:
Nov 03, 2021 08:23 PM
Count me in on the sandwich bet!! :laughing: :sandwich:
Nov 04, 2021 04:59 AM
Nor should you care. Here’s why… integrations should exist without the influence of users who may apply various sort order changes which would create a degree of brittleness at the integration layer.
If order is what you seek, allow Airtable’s server (or your server-side code) to do it. But above all, do not create dependencies that can be abruptly changed by anything external to the integration itself.