Skip to main content
Solved

Function parameters as JSON key in Node.js

  • June 2, 2022
  • 2 replies
  • 17 views

Forum|alt.badge.img+6
  • Inspiring
  • 20 replies

Hello, How do I pass function parameters as JSON field name for updating fields in Airtable using Airtable REST API and Node.js?

The code

const updateField = async (id, field_name, updateValue) => {

  base('table_name').update([
    {
      "id": id,
      "fields": {
        field_name: updateValue
      }
    }
  ], function (err, records) {
    if (err) {
      console.error(err);
      return;
    }
  });
}

Best answer by kuovonne

Is this what you need?
[field_name]: updateValue

2 replies

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • 6009 replies
  • Answer
  • June 2, 2022

Is this what you need?
[field_name]: updateValue


Forum|alt.badge.img+6
  • Author
  • Inspiring
  • 20 replies
  • June 2, 2022

Is this what you need?
[field_name]: updateValue


Works!
Thank you for pointing out the silly mistake!