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}
})
}