I keep running into INVALID_FILTER_BY_FORMULA errors when trying to filter my Airtable records through the API. The documentation isn’t very clear on the correct syntax.
I’m specifically struggling with creating AND conditions and NOT operations. Here are some examples that aren’t working:
// These all throw errors
filterByFormula: "NOT({reviewStatus}='declined')"
// filterByFormula: "NOT({title} = '')"
// filterByFormula: "{category} = 'draft' AND {processStatus} = NOT('complete')"
// filterByFormula: "NOT ({processStatus} = 'complete')"
// filterByFormula: "{processStatus} = NOT('complete')"
I figured out that for NOT operations I can use {category} != 'empty' but I need help with more complex filtering patterns. Does anyone have working examples of compound filters?
You’re mixing JavaScript syntax with Airtable formulas - that’s the problem. I did this constantly when I started with filterByFormula. Your NOT needs to wrap the whole condition, not just the value. So NOT({reviewStatus}='declined') works if you URL encode it right. The real killer is complex AND statements. Structure them as AND(condition1, condition2, condition3) instead of && operators. Double-check your field names match exactly - case matters. I’ve wasted hours on filters that broke because of one lowercase letter. Test formulas directly in Airtable before throwing them into API calls.
Those syntax errors are from bad operator placement and missing URL encoding. I spent weeks debugging this exact stuff when I started with Airtable’s API. Your NOT syntax is right sometimes, but URL encoding is probably the real issue. When you send NOT({reviewStatus}='declined') through the API, you’ve got to encode the parentheses and equals signs properly. For multiple conditions, wrap everything in AND() like AND({category}='draft', {processStatus}!='complete'). The != operator usually works better than NOT for simple exclusions. Double-check your field names match exactly too - I’ve had filters break because of hidden spaces in field names that don’t show up in the interface.
hey! i’ve hit this same issue. you need airtable formula syntax, not javascript logic. try AND({category}='draft', NOT({processStatus}='complete')) instead. and don’t forget to url encode it in your request - i’ve been burned by that so many times lol