Help

Re: Issue with "sorting" through API

1160 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Mehmet_YILDIZ
4 - Data Explorer
4 - Data Explorer

Hi all,

I’m having hard time with “sort” through API. Whatever I tried got me INVALID_REQUEST_UNKNOWN error (message: Invalid request: parameter validation failed. Check your request data.)

Here is the browser JS code I render the final request url:

var rUrl = ‘https://api.airtable.com/v0/…/Data?api_key=…’;
rUrl += ‘&filterByFormula=’ + encodeURIComponent(“AND({Pub}=’’,NOT(LEFT({Name},3)=’###’))”);
rUrl += ‘&sort=’ + encodeURIComponent("[{‘field’:‘PID’,‘direction’:‘asc’}]");

Here is the final bundled request I make;

https://api.airtable.com/v0/…/Data?api_key=…&filterByFormula=AND(%7BPub%7D%3D%27%27%2CNOT(LEFT(%7BName%7D%2C3)%3D%27%23%23%23%27))&sort=%5B%7B%27field%27%3A%27PID%27%2C%27direction%27%3A%27asc%27%7D%5D

Removing sort from url always works but I tried many different versions of the sort value as well as different urlencoding/non-encoded versions. What am I doing wrong?

2 Replies 2
Tuur
10 - Mercury
10 - Mercury

Hi there!

The final URL request has to look something like…

&sort[0][direction]=desc

Let me know when you need more. :slightly_smiling_face:

Edit: non-escaped example of course…

You can use this to see what the proper URL-encoded parameters for your request should be: https://codepen.io/airtable/full/rLKkYB