Apr 27, 2018 08:54 AM
I am trying to understand the way to formulate either an API call that matches a filtered view on a table I have set up – a base that has date serving, name, venue name, address, zip code, time starting, time ending and cache. I have the filter by in the view of the table set to filter by a specific day and zip code to filter for the first three numbers of the zip code and of course this provides exactly the information I want.
My question is, how do I translate this view into an API call so that in a table with multiple entries I receive the information that translates to this more limited scope?
Apr 27, 2018 09:37 AM
The Airtable API provides you with a neat parameter called “filterByFormula”…which you can pass as parameter along with you HTTP call.
You can set this parameter to the formulae you want to to filter your bases by.
Your formulae would look something like
AND(zipcode=“333”, date=“5/5/18”)
The formulae has to be URL encoded.
They also provide you with a parameter called “view” which you can pass along with your HTTP call.
You can set the view parameter to the name of the “filtered view” on your table you are intrested in
Apr 27, 2018 09:49 AM
To clarify, would the view
parameter honor the filtering already present in the Airtable view? IE, any records not showing in the view do not exist as far as the API is concerned?
Apr 27, 2018 09:55 AM
Andrew, Thanks for replying to my question, I believe I have attempted this before and received this same INVALID_FILTER_BY_FORMULA result, if you look at the relevant part of my url could you advise me what’s wrong? url …Table%201?&filterByFormula=AND(zip+code=“296”,%20date+serving=“2018-04-30”)&
I would greatly appreciate it, needless to say the information to the left and right of the text is base number and api key and the + have been added to the zip code and date serving because of the text space.
Apr 27, 2018 10:03 AM
Yes it would honor it.
Apr 27, 2018 10:27 AM
You need the quotes, commas and equal sign to also be URL encoded…
It would look something like this.
filterByFormula=AND(zip+code%3D%22296%22%2Cdate+serving%3D%222018-04-30%22)
Apr 27, 2018 11:12 AM
Andrew I really am not sure what the issue is, to answer your first question, yes it would accept those exact parameters as filters and supplies the results in the view, I have tried both your url encoded filter by formula as well as the formula that I have marked as codepen from the codepen resource that airtable has provided, unfortunately something must be wrong as both times the api response is {
“error”: {
“type”: “INVALID_FILTER_BY_FORMULA”,
“message”: “The formula for filtering records is invalid: please check your formula text.”
}
}
This is your formula:
filterByFormula=AND(zip+code%3D%22296%22%2Cdate+serving%3D%222018-04-30%22)
Codepen formula
filterByFormula=AND(zip+code%3D“296”%2C+date+serving%3D“2018-04-30”)&maxRecords=10&view=Grid+view
I have absolutely no idea what is wrong, I am hitting the api, I am authorizing the query and the table and view and items are filterable by the parameters I am using.
Apr 27, 2018 04:08 PM
So In case any one is following this thread the field name needs to be wrapped in curly’s, as an example: AND({dateserving}=“04/30/2018”, {zipcode}=“14131”) which will yield this url string filterByFormula=AND(%7Bdateserving%7D%3D%2204%2F30%2F2018%22%2C+%7Bzipcode%7D%3D%2214131%22) Hope anyone else ever struggling with this finds this helpful.