Updating records in Airtable returns 422 error

This topic was automatically generated from Slack. You can find the original thread here.

Mohammed Zeeshan : Hi!
I am trying to update an airtable record using 2 event steps 1. listing records 2. updating records

Listing records returns the details as expected but when i try to update the record by mapping the record from the previous step, it doesn’t show up
I tried manually adding the record-id but it returned 422. I haven’t yet added the fields to be updated at this point. What would be missing? can anyone point to the right direction? Thanks :pray:

Dylan Sather (Pipedream) : typically the 422 error from Airtable suggests that something about the record update payload is malformed.

Take a look at this example - I format the update request in the first step, and pass that to the next step as the value of the Records param. I’ve turned structured mode Off in this example, which allows me to pass an array of record updates directly from a previous step (see our docs on structured params for more info).

Let me know if that helps.

Mohammed Zeeshan : I copied your same workflow but still returning 422 error :thinking_face: I did double check with the table id and base id.

Dylan Sather (Pipedream) : Do you see how I’ve got an id in my records? That refers to the record ID, and needs to be included in the update request

Dylan Sather (Pipedream) : I’d recommend taking a look at the Airtable API docs for updates, which might help: REST API - Airtable

Mohammed Zeeshan : Oh i see! I assumed that only table-id and base-id is required.

I am looking for a way to find the recID using filterbyformula which returns the recID. This part works fine.

And then in next step use that recID to refer for updating another field of that same record.

Dylan Sather (Pipedream) : ```
this.records = [
{
fields: {
“YOUR FIELD”: “YOUR VALUE”,
},
id: steps.YOUR_STEP_THAT_FINDS_THE_RECORD.RECORD_ID, // replace with the variable reference to the record ID
},
]

Dylan Sather (Pipedream) : I believe you’ll just need to fill in the record ID with the reference to the record returned by your find step. Am I misunderstanding you?

Dylan Sather (Pipedream) : once you’ve correctly formatted the update payload with the fields and id, you should be able to pass that to the update step

Mohammed Zeeshan : Great, so that means it needs 3 steps at total, right?
Find step, format step and update step
and this worked :sweat_smile::star-struck:

Dylan Sather (Pipedream) : great! Yes, with the Airtable API, since they expect that format for updating records, you’ll need to get your update request into that form

Mohammed Zeeshan : Got it! Thanks. But again, i was wondering how could we update fields here while it doesn’t show the field name like Zapier :thinking_face:
Basically i simply want some strings to go into a field in airtable

Dylan Sather (Pipedream) : Currently there is not an easy way for us to infer the fields like Zapier does, but that’s great feedback. I’ll look into their approach.

Mohammed Zeeshan : Yeah this would be great! Currently our project revolves around this so would need to switch back to Zapier for this part

Mohammed Zeeshan : I tried passing values to the field this way but returns a syntax error unexpected token :

Dylan Sather (Pipedream) : Airtable expects an array of objects. Unfortunately what you’re passing isn’t valid JavaScript (you’re trying to define an object without wrapping it in { }. You should be able to pass the array of objects directly inside of the Records param, though:

{{ [
  { 
    fields: {
      "YOUR FIELD": "YOUR VALUE",
    },
    id: steps.YOUR_STEP_THAT_FINDS_THE_RECORD.RECORD_ID, // replace with the variable reference to the record ID
  },
] }}

Mohammed Zeeshan : Oh gotcha!

I am adding this to our original format step

Mohammed Zeeshan : One thing i notice is that

Adding values as recID works well and the airtable gets updated
but…
i want to add some strings from the previous steps which results in 422 error (yikes)

Dylan Sather (Pipedream) : what’s the value of steps.nodejs_3.$return_value?

Mohammed Zeeshan : It is some string