Help

Re: What is the default order or records in a get request when no view or sort order is applied

5464 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Cameron_Flanaga
5 - Automation Enthusiast
5 - Automation Enthusiast

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.

19 Replies 19

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.)

Cameron_Flanaga
5 - Automation Enthusiast
5 - Automation Enthusiast

No Problem Thank you for clarifying I figured as much after testing but wasnt certain. Suppose this can be closed now.

@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?

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.

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.

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”.

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:

image

Count me in on the sandwich bet!! :laughing: :sandwich:

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.