Oct 09, 2024 02:51 AM
i have this piece of code
try:
# Step 1: Search for the record with the given unique ID
print("stage 1")
search_url = f'{url}?filterByFormula={{Part unique No 1}}="unique_id"'
print("stage 2")
search_response = requests.get(search_url, headers=headers)
print(search_response)
if search_response.status_code == 200:
search_result = search_response.json()
if search_result['records']:
# Step 2: If record is found, extract the record ID and existing quantity
record_id = search_result['records'][0]['id']
existing_fields = search_result['records'][0]['fields']
existing_quantity = existing_fields.get('Quantity', 0)
# Step 3: Add the new quantity to the existing quantity
updated_quantity = existing_quantity + int(new_quantity)
# Step 4: Prepare the data for the update
update_data = {
"fields": {
"Quantity": updated_quantity,
"keptBy": kept_by,
"location": location
}
}
# Step 5: Send the PATCH request to update the record
update_url = f'{url}/{record_id}'
update_response = requests.patch(update_url, json=update_data, headers=headers)
what it does is it searches my air-table base in a particular field("Part unique No 1") whether it matches with ("unique_id") if it matches it updates that particular row of that particular ("Part unique No 1")
but, the issue is it's not working the way it should be... what i think i'm using filter by formula in a wrong manner.
help by anyone would be appreciated..
thankyou in advance
Oct 09, 2024 03:56 AM
Hello @Nirbhay29,
Instead of using this
filterByFormula={{Part unique No 1}}="unique_id"
Try this
filterByFormula=AND({Your Field Name}='your value')
Another important thing is to check my 2 other responses for the same kind of post.
1. https://community.airtable.com/t5/development-apis/problems-using-filterbyformula-with-a-special-cha...
2. https://community.airtable.com/t5/development-apis/search-for-the-record-with-the-given-unique/td-p/...
Please mark any response that helps you as the solution. This helps the community by indicating which responses are most helpful. 👍
Oct 09, 2024 11:11 PM
Thanks for sharing those links! I'll definitely check them out. I appreciate the reminder about marking helpful responses as the solution—I'll be sure to do that if I find what I'm looking for. Thanks again!