Help

Confused by API

1227 1
cancel
Showing results for 
Search instead for 
Did you mean: 
ilyakoyfman
4 - Data Explorer
4 - Data Explorer

Hey all,

I am relatively new to using the Airtable API, and I might just be confused. I am hoping you all can steer me in the right place.

I am used to using APIs to do things, but the Airtable Scripting Api seems weird to me.

To my understanding, when I GET a record, I am only getting the record object with very little fields. Do I need to call getCellValue on all the fields to actually pull out the data or is there a better way to get the data out?

1 Reply 1
goksan
6 - Interface Innovator
6 - Interface Innovator

Hey @ilyakoyfman 👋

I'm not sure whether there's any shortcuts aside from iterating over the field names and calling getCellValue

Here's an example that builds an object that maps field names to field values for a given record:

const tableFields = base.getTable("TABLE").fields
const rec = await base.getTable('TABLE').selectRecordAsync('RECORD_ID')
const allData = tableFields.reduce((acc, field) => {
    return {...acc, [field.name]: rec?.getCellValue(field.name)}
}, {})
console.log(allData)