Jun 18, 2024 08:19 AM - edited Jun 18, 2024 09:52 AM
Hi,
i am using python-requests and trying to use f-string with filterByFormula here is a simple implementation:
hard coding the name worked:
url=f"https://api.airtable.com/v0/{base_id}/{table_name}/"
headers={'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'}
query={"filterByFormula":"({full_name}="some name")"}
response=requests.get(url, headers=headers, params=query)
data=response.json()
but when i tried to use f-string it didn't work. here is a a piece of code where the problem occurred:
url=f"https://api.airtable.com/v0/{base_id}/{table_name}/"
headers={'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'}
employee_name="some name"
query={"filterByFormula":f"{{full_name}}={employee_name}"}
response=requests.get(url, headers=headers, params=query)
data=response.json()
{'error': {'type': 'INVALID_FILTER_BY_FORMULA', 'message': 'The formula for filtering records is invalid: Invalid formula. Please check your formula text.'}}
i wish somebody can help me with this
thanks
Solved! Go to Solution.
Jun 18, 2024 02:04 PM
I've found my mistake and i will post it here for reference for others:
the wrong code:
query={"filterByFormula":f"{{full_name}}={employee_name}"}
the right code (use single quotes for the '{employee_name}'):
query={"filterByFormula":f"{{full_name}}='{employee_name}'"}
the parameter placeholder must be in single quotes.
Jun 18, 2024 02:04 PM
I've found my mistake and i will post it here for reference for others:
the wrong code:
query={"filterByFormula":f"{{full_name}}={employee_name}"}
the right code (use single quotes for the '{employee_name}'):
query={"filterByFormula":f"{{full_name}}='{employee_name}'"}
the parameter placeholder must be in single quotes.