Help

Amend records using API

Topic Labels: API
4423 5
cancel
Showing results for 
Search instead for 
Did you mean: 
Jonathan_Coulta
6 - Interface Innovator
6 - Interface Innovator

Is it possible to amend records using API without losing linked fields?

5 Replies 5
Giovanni_Briggs
6 - Interface Innovator
6 - Interface Innovator

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"
      }
    }'

Very helpful thank you.

LukaszWiktor
6 - Interface Innovator
6 - Interface Innovator

Is there a corresponding function in airtable.js?

Ah, just figured out that update is an equivalent for PATCH, and replace makes use of PUT.

EJ_Alexandra
4 - Data Explorer
4 - Data Explorer

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:

  1. GET the entire current record
  2. Loop through this little local 3 field version of the object and update all fields on the full record.
  3. Then PUT 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.