How to filterByFormula a multiselect field?

Hello, I am using AppGyver as my front end.

From a multiselect field in AppGyver, User A chooses “red”, “blue”, “green”, “purple”. I want to pull all records from my Cloth table which have those 4 colours

From a multiselect field in AppGyver, User B chooses “pink”. I want to pull all records from my Cloth table which have pink.

I do not know in advance how many criteria the user will select.

I know i can sort by multiple fields using an array → ?sort[0][field]=day&sort[0][direction]=asc&sort[1][field]=name&sort[1][direction]=desc (of course the whole query parameter needs to be encoded)

But i don’t know how to do that for filters through API cause API filtering is done through filterByFormula → and if i were to use an OR function, i need to know how much filters there are in advance e.g. user will choose 1 colour, or 2 colours, or 3 colours etc

Could someone kindly teach me how I can get this done in AppGyver linking to Airtable? Thanks!

Correct - this is what’s known as a late-binding operation; you must generate the API query for each condition presented by each user. Typically this is done by constructing the query string dynamically for each user’s request and then using the Airtable API to make the query.

Ergo, given an array of colors, build a query string to satisfy the API call using filterByFormula.

1 Like

hi Bill! thanks for your help once again, i took quite long to respond as i wanted to do sufficient research and have a proper reply :slight_smile:

late-binding operations - this sounds very interesting

Question 1) how do i generate the query string dynamically?
Question 2) do i need to use javascript to generate the query string?
Question 3) can i use cURL to generate the query string?

i am familiar with javascript but when it comes to cURL i’m confused because Airtable documentation lists cURL and Javascript as alternatives, but cURL to my knowledge its a command line interface, i can only type one line and press enter to run that single line, then the next line runs one by one, but for javascript i can type out a do while loop, switch statements etc. cURL vs javascript seem like very different “beasts”

P.S. i’ve been reading a few other posts you made on a few other topics and will add on to them soon once i further streamline my contribution! :slight_smile:

By concatenating values and field names - something like this in javascript:

const query = '?filterByFormula=';
        const filterBy = `SEARCH("${req.params.name}", {Name} )`;
        const link = `${URL}${query}${filterBy}`;

The idea is to assemble the query as a string and then use it to execute the query.

No. cURL is a command line utility to test HTTP requests; this is unhelpful in actually performing automated processes.

This topic was solved and automatically closed 15 days after the last reply. New replies are no longer allowed.