May 04, 2019 06:42 PM
Is it possible to amend records using API without losing linked fields?
May 05, 2019 10:51 AM
There are different ways to update a record – PUT and PATCH. PUT will update all fields in a record. So if you do not include certain fields in the request, that is equivalent to setting them to null (clearing their value).
A PATCH request will only update the fields that you include in the request. Any fields you leave out will keep their existing value.
So it sounds like you want to issue a PATCH request to update some values of an existing record, but not all of them.
curl -v -XPATCH https://api.airtable.com/v0/{BASE_ID}/{TABLE_NAME}/{RECORD_ID} \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"fields": {
"field1": "some new value",
"field4": "a different value"
}
}'
May 06, 2019 09:23 PM
Very helpful thank you.
Jun 07, 2019 07:40 AM
Is there a corresponding function in airtable.js?
Jun 07, 2019 07:43 AM
Ah, just figured out that update
is an equivalent for PATCH, and replace
makes use of PUT.
Oct 06, 2019 03:28 PM
As a follow on question, is there any way to clear/empty a field with such a patch though?
Or must one have access to the entire record in order to empty out any specific field (i.e. do a PUT
)?
In other words, if the entity making the request knows only
{ FirstName:"john",MiddleName:"" }
, then a PATCH
feels like the right update mechanism.
This would blank out Middle name, even with a PATCH
- but what if we want to blank out a Date field? This does not work- because “” is not a valid date.
{ FirstName:"john",MiddleName:"", DateOfBirth:"" }
And if we don’t provide a value with PATCH
, it just leaves the previous date of birth.
So is the only way to clear out a previously set field to:
GET
the entire current recordPUT
the full (updated) record back (potentially overwriting any values updated between steps 1 and 3)Is this really the only way to clear out a field through the API? This feels both heavy handed for something as simple as setting a field to NULL, as well as error prone.
If anyone has any other suggestions as to how to deal with this - I would be greatly appreciative.