Skip to main content

How can I prevent the "INVALID MULTIPLE CHOICE OPTIONS" error?

  • November 12, 2017
  • 8 replies
  • 364 views

Forum|alt.badge.img+1

Hi

I’m trying to add data to a table using the API, one field of which is a ‘Multiple Choice’ field, so i’m passing data as an array.

However, it will only accept the POST if the table has predefined multiple choice options and you’re sending a POST with one or more those options, else it throws a ‘INVALID_MULTIPLE_CHOICE_OPTIONS’ error.

And, from what I see you cannot create multiple choice options by using the API either.

I assume this is expected behaviour, but… is there a way of programmatically adding new options to a multiple choice typed field, or even getting a list of acceptable values for that field, so i can check the data before calling the API?

Thanks!

mk

8 replies

Forum|alt.badge.img+19
  • Inspiring
  • 366 replies
  • November 13, 2017

Not that I’m aware of. Everything metadata related is basically non-existent.


Forum|alt.badge.img
  • New Participant
  • 1 reply
  • July 16, 2018

I’m also having this problem. How can I create a record that has a “multiple choice” column for values that are going to be an unknown set of “tags”? So far the only work-around I have found is to set the column type to be a “single line text” and upload my tags as a comma-delimited string, then when I am done with the API, going to the graphical interface and converting the column type to be a multi-select.


Forum|alt.badge.img+7
  • New Participant
  • 4 replies
  • October 4, 2018

Having this problem as well. Unfortunately, the API gives you no way of creating the new options. I’m having to forego the nice pill formatting to just string delimit my values. Another option if you are just wanting the pill formatting would be to make a lookup table that you can write the new values to, then send an array of those value ids from the lookup table as an array to your original linked column; that’s more work than I want to do at the moment though.


  • New Participant
  • 1 reply
  • December 12, 2018

One solution that worked for me is to convert the column to a single line text type. Import your data, and then switch back to single select and it will automatically use the existing values to initialize the set of options.


  • New Participant
  • 3 replies
  • January 24, 2020

It works when you use the {typecast: true} parameter
example:

base(‘Deal’).create({
“Quantity”: 720,
“PaymentMethod”: “Cash”,
}, {typecast: true}, function(err, record) {
if (err) {
console.error(err);
return;
}
console.log(record.getId());
});


Forum|alt.badge.img
  • New Participant
  • 1 reply
  • May 13, 2020

For some more context, this is what the Airtable API’s documentation says when you look at a “Single select” or “Multiple select” field:

When creating or updating records, if the choice string does not exactly match an existing option, the request will fail with an INVALID_MULTIPLE_CHOICE_OPTIONS error unless the typecast parameter is enabled. If typecast is enabled, a new choice will be created if one does not exactly match.


Forum|alt.badge.img
  • New Participant
  • 1 reply
  • November 10, 2021

Here is an example of where to add the typecast

var Airtable = require('airtable');
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('baseId');

base('Table 1').create([
  {
    "fields": {}
  },
  {
    "fields": {}
  }
], {typecast: true}, function(err, records) {
  if (err) {
    console.error(err);
    return;
  }
  records.forEach(function (record) {
    console.log(record.getId());
  });
});

Forum|alt.badge.img+1
  • New Participant
  • 1 reply
  • March 24, 2023

Example for python users, very similar. I use this function to call up the format and then just drop w.e. data I'm working on in.

def get_json_obj(typecast=True, fields_to_merge_on="Name", perform_upsert=True): """ if perform_upsert: json_obj = { "performUpsert": { "fieldsToMergeOn": [ fields_to_merge_on ] }, "records": [], "typecast": typecast } else: json_obj = { "records": [], "typecast": typecast } return json_obj