Getting all records modified after a date

Hello,

I’m using the Airtable Python wrapper found here: Airtable Python Wrapper Documentation — Airtable Python Wrapper documentation
I’m trying to get all records modified after some date time. My code is:

AT = Airtable(BASE_KEY, TABLE_NAME, API_KEY)

filterByFormula = ‘IS_AFTER(LAST_MODIFIED_TIME(), DATETIME_PARSE(“2022-03-15T14:23:41.000Z”))’

AT_ITER = AT.get_all(formula=filterByFormula)

However, this is always returning every record in the table. Also, how do I get it to return the last modified date in the fields? I have tried:

AT_ITER = AT.get_all(formula=filterByFormula, fields=“lastModifiedTime”)

…but this throws an error. The docs say the default is to return all fields, but there’s no modified date field when I try that, either.

Any help, please?

Thanks!

-Dan

For last modified field: have you tried making a formula field (col) that ‘calculates’ the last modified date?

LAST_MODIFIED_TIME()

Maybe the API will ‘see it’ when turned into a field explicitly.

1 Like

When using filterByFormula, it is good practice to test out the formula by creating a formula field in the base with the formula in it. The quotes around your formula also look a bit strange.

Thanks, but, unfortunately, it’s not my Airtable. I have to query a client’s Airtable for a service my company provides so I can’t really use it as a sandbox.

The quoting is because it’s written in Python. You can’t pass a string to a function in Python without quotes. In any case, the function doesn’t throw an error so it appears it’s able to digest the formula.

The question is, why doesn’t it appear to work as expected?

I don’t know how your Python code forms the url parameters for the request, but the API documentation shows that before url encoding, the filterByFormula parameter should not have quotes in it. If the formula is completely enclosed with quotes, then the formula is basically just a text string, and it will always evaluate to true.

Even though you cannot test the formula in your client’s actual base, you should be able to create a base of your own with similar fields and data to test the formula.

Conversion of the string to an actual formula Airtable understands is handled by the Python wrapper as can be seen here: Parameter Filters — Airtable Python Wrapper documentation
This is a very common schema for many programming languages. There are only four base object types in Python - numbers, booleans, datetimes and strings. Since the other three base object types can’t hold a complex query it must be passed as a string and then parsed by the function you pass it to.

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