Skip to main content

I have an external API using, which I’m getting a list of the items.

Items object/array is having a field name = title

I want to update only records for which title matches

AT also have a field name “title”

but this is not working as expected. it;s not aligning the correct records.


let table = base.getTable('Data');
let view = table.getView("CMS Data");
let query1 = await view.selectRecordsAsync({
sorts: o
{field: "Title"},
]
});

let response = await fetch('https://<api-url>/endpoint?_format=json', {
//method: 'GET',
});

let query = await response.json();
let peopleTable = base.getTable('Content');

for (var i in query) {
recordId = query1.recordsei].id;
if( query1.recordsei].getCellValue("Title") == query i].title ) {
let cms_id = query i].id;
await peopleTable.updateRecordAsync(recordId, {
"id": Number(cms_id),
})
}
}

Your script is using the same index for both the data from Airtable and the API. However, the indexes for the two datasets do not align. They might even be different lengths.


I suggest you read Bill French’s post on how to deal with situations like this.



Reply