Help

Filtering views in the API read

Topic Labels: API
9767 7
cancel
Showing results for 
Search instead for 
Did you mean: 
Elizabeth_Barr
5 - Automation Enthusiast
5 - Automation Enthusiast

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?

7 Replies 7
Andrew_Johnson1
8 - Airtable Astronomer
8 - Airtable Astronomer

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

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?

Elizabeth_Barr
5 - Automation Enthusiast
5 - Automation Enthusiast

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.

Yes it would honor it.

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)

Elizabeth_Barr
5 - Automation Enthusiast
5 - Automation Enthusiast

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.

Elizabeth_Barr
5 - Automation Enthusiast
5 - Automation Enthusiast

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.