Help

Discover what data silos are costing your org in our commissioned Forrester study. Learn more

Sort single select field via API

Solved
Jump to Solution
726 9
cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I am currently connecting to airtable data via the API. I am able to sort my response in certain fields using desc and asc. However for non text fields in particular single select fields where in the UI you would sort First-Last. What would the parameter be for sorting these fields?

1 Solution

Accepted Solutions

The sort order for Single Select fields is not evaluated alphabetically… it is evaluated by the order that your single select options are listed within the field customization options.

You can see this within the Airtable interface itself by trying to sort on a single select field.

If you want them alphabetically, you have to manually alphabetize the options within the Airtable interface by clicking on the “sort alphabetically” button within the field options (or you can manually alphabetize them).

Alternatively, you could create a formula field that equals the single select field, and then sort by that formula field instead.

See Solution in Thread

9 Replies 9

Welcome to the community, @Cameron_Flanagan!

That isn’t possible with the “sort” parameter, but you can specify a “view” parameter instead of a “sort” parameter. In that case, the API will sort your records as they appear in that particular view.

One very important thing to note is that your records can NOT be grouped in your view. Your records must be ungrouped. If they are grouped, Airtable will sort your records in its own random unpredictable order. This is a bug in Airtable.

Thank you for the reply scott. The issue with the views is that is doesnt allow nice interaction with the data in custom UI over the top of the API. It seems rather restrictive. So are you saying there is no way to sort data that isnt of type long text or short text via the API?

Not sure what you’re asking or what you’re trying to accomplish. You can sort on any field you want, not just long text or single line text fields.

Hi Scott, Apologies for the confusion here.

The issue I am having is when making get requests to the airtable API using the sort parameter defined in the documentation.
sort%5B0%5D%5Bfield%5D=STUDY%20NAME
sort%5B0%5D%5Bdirection%5D=desc
This works for me for certain fields. But when I do the same thing for a field that is a single select field the response I get back does not appear to be sorted in anyway. So am I doing something wrong is there another value I should pass for direction for these type of fields?

I just tested this on my end, and it works just fine for me. Are you sorting on more than one field in your Get Request, or just the one field? Why don’t you post your entire Get Request here.

This is just one field. This is working for other types of field but when I do something like the below where N is a single select field the results do not come back in a sorted order.
[14/07/2021 10:18] Flanagan, Cameron

curl "https://api.airtable.com/v0/appS0WN8ilWEOG0Ie/Trials%20Database?maxRecords=3&view=Grid%20view&sort%5... \

-H “Authorization: Bearer {{API_KEY}}”

The sort order for Single Select fields is not evaluated alphabetically… it is evaluated by the order that your single select options are listed within the field customization options.

You can see this within the Airtable interface itself by trying to sort on a single select field.

If you want them alphabetically, you have to manually alphabetize the options within the Airtable interface by clicking on the “sort alphabetically” button within the field options (or you can manually alphabetize them).

Alternatively, you could create a formula field that equals the single select field, and then sort by that formula field instead.

Thanks Scott this has cleared things up. After doing the sort in the UI results are returned as expected.

Glad I could help! :slightly_smiling_face: If you don’t mind, could you please mark my comment above as the solution to your question? This will help other people who have a similar question in the future. :slightly_smiling_face: