Help

Re: troubleshooting updateRecordAsync

Solved
Jump to Solution
873 0
cancel
Showing results for 
Search instead for 
Did you mean: 
mcordier
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi all,

I'm creating an automation to retrieve data from an endpoint then update a record in Airtable.
The api call works, the data is formatted into a string, and correctly passed into the `updateRecord` function.
However I'm getting the following error when testing the automation:
Error: Request parameters failed validation.

Here is the code:

 

 

let inputConfig = input.config();
let table = base.getTable('Orders');
let record = inputConfig.recordId;

fetch(`https://api.myEndpoint/${record}`, {
  method: "GET",
  withCredentials: true,
  headers: {
    "Authorization": inputConfig.apiKey,
    "Content-Type": "application/json"
  }
}).then((response) => {
    return response.json().then((data) => {
      updateRecord(data)
      return data
    })
  })

const updateRecord = async (data) => {
    let status = data.status
    await table.updateRecordAsync(recordId, {
      "Status": status,
  })
}

 

 

 To follow up, I modified the code to query the table and pull the latest created record and the update works.
I don't understand why we'd need to go through this extra step. Any insight or correction is appreciated.

This works but I don't know why it's necessary vs the first code example:

 

 

let inputConfig = input.config();
let table = base.getTable('Orders');
let query = await table.selectRecordsAsync({
  fields: ["Order #", "Status"],
  sorts: [{field: "Order #"}]
})
let recordId = query.records[query.records.length - 1].id // Unique identifier for a line item in order ex. rec9xNNtedRGoQZEY
let recordName = query.records[query.records.length - 1].name // The order number ex. 13247

fetch(`https://api.myEndpoint/${recordName}`, {
  method: "GET",
  withCredentials: true,
  headers: {
    "Authorization": inputConfig.apiKey,
    "Content-Type": "application/json"
  }
}).then((response) => {
    return response.json().then((data) => {
      updateRecord(data)
      return data
    })
  })

const updateRecord = async (data) => {
  let status = data.status
    
    await table.updateRecordAsync(recordId, {
        "Status": {"name": status}
    })

}

 

 

1 Solution

Accepted Solutions
Alexey_Gusev
12 - Earth
12 - Earth

Hi,

You need to pass record name to fetch function (in https link). Record name is a value of primary field. String like 'rec123qwe456..' is record ID. You can just add recordName in input parameters, left side of automation script step UI, and then retrieve it from input.config().

but it's not only 'Name' vs 'ID' makes the difference.

I guess your field 'Status' is single-select.
You cannot just put string 'Option1' (for example) there. You should put object  {name:'Option1'} to update 'Status' in record. Also, 'Option1' should already be present in field settings.

See Solution in Thread

2 Replies 2
Alexey_Gusev
12 - Earth
12 - Earth

Hi,

You need to pass record name to fetch function (in https link). Record name is a value of primary field. String like 'rec123qwe456..' is record ID. You can just add recordName in input parameters, left side of automation script step UI, and then retrieve it from input.config().

but it's not only 'Name' vs 'ID' makes the difference.

I guess your field 'Status' is single-select.
You cannot just put string 'Option1' (for example) there. You should put object  {name:'Option1'} to update 'Status' in record. Also, 'Option1' should already be present in field settings.

mcordier
5 - Automation Enthusiast
5 - Automation Enthusiast

Thanks @Alexey_Gusev !

I updated my input.config to give me the value of the Airtable record ID and passed that as the first argument to the updateRecordAsync function. The test now passes with the correct data being updated.

Good catch on the single-select, too.