REST API mixes up sequence of data in Airtable

Good day Draftbit Community,
I have a table in my Airtable base that looks like this,

image

I’ve added it to Draftbit using REST, but the records aren’t showing up in order,
for example,

image

And in Data you can see that the first record does not match the first record in Airtable.
.

They don’t appear to be sorted by anything and the order seems random.
This doesn’t appear to be a problem with Draftbit, so I’m guessing it’s just Airtable or the API.
How do I sort it so that the days appear in order?

Thanks,
William

Hi William,

Sorry you’re running into this but thanks for pointing this out, I’m going to take a look. It’s possible to sort your records in ascending order (example here) but you shouldn’t have to in this case. I’ll reach back out once it’s been fixed!

Thanks,
Angela

1 Like

Hey William – Angela is right, I think all you need to do is add a sort parameter to your fetch requests. You can read more about the sort parameter in the Airtable API documentation, but here’s a snippet:

sort

A list of sort objects that specifies how the records will be ordered. Each sort object must have a field key specifying the name of the field to sort on, and an optional direction key that is either "asc" or "desc". The default direction is "asc".

The sort parameter overrides the sorting of the view specified in the view parameter. If neither the sort nor the view parameter is included, the order of records is arbitrary.

For example, to sort records by Name in descending order, send these two query parameters:

sort%5B0%5D%5Bfield%5D=Name
sort%5B0%5D%5Bdirection%5D=desc
For example, to sort records by Name in descending order, pass in:

[{field: "Name", direction: "desc"}]

Another way to do this would be to create a view that is sorted in Airtable, and use that view in your fetch request.

Hope this helps!

1 Like

I found an excellent guide by Angela on Sorting and Filtering Airtable Requests using an API Encoder.
I created an extra field called DayNum with Monday having 1, down to Friday’s 5, and I sorted by that and had the view set to DayName(new name for the field with the days).

And now it works in order!
Thanks to you both for your help!

1 Like

Awesome, glad you got it to work! :smile:

1 Like