Help

Re: NPM Airtable help with adding options to a multiple select field

Solved
Jump to Solution
4203 3
cancel
Showing results for 
Search instead for 
Did you mean: 
masterconquero
4 - Data Explorer
4 - Data Explorer

I have a board where I track ice cream names and the flavours they come in. Names are self generated where are flavours are common names such as vanilla or chocolate and so on.

I want to use the npm airtable code here:

https://www.npmjs.com/package/airtable

and what I want to achieve is if a new flavour is added to the list of flavours, I want to also add this new flavour to the list of options available on the Airtable multiple select field. I am trying to mimic the code here:

https://airtable.com/developers/scripting/api/field#update-options-async

const table = base.getTable("Tasks");
const selectField = table.getField("Priority");
await selectField.updateOptionsAsync({
    choices: [...field.options.choices, {name: "Urgent"}],
});

However using the npm package it seems these functions are not available.

I also tried using Curl as below:

curl --request PATCH \
  --url https://api.airtable.com/v0/meta/bases/{baseId}/tables/{tableId}/fields/{fieldId} \
  --header 'Authorization: Bearer {myToken}' \
  --header 'Content-Type: application/json' \
  --data '{
		"options": [{"name": "a"}, {"name":"b"}, {"name":"c"}]
}'

Using the curl above I wanted to see if I could add a, b, and c as options to the field. However I received the following error:

{
	"error": {
		"type": "INVALID_REQUEST_UNKNOWN",
		"message": "Invalid request: parameter validation failed. Check your request data."
	}
}

I am currently trying to understand if this is at all possible. Any guidance would be appreciated. 🙂

1 Solution

Accepted Solutions
goksan
6 - Interface Innovator
6 - Interface Innovator

Hey @masterconquero 👋

There's no explicit way of creating options via the API (even with the latest API releases to my knowledge)

There is however the`{typecast: true}` method, here's an example from a test in the airtable.js library

The documentation for your base should contain the following if you want to do further reading:

Screenshot 2022-12-06 at 14.31.56.png

See Solution in Thread

9 Replies 9
goksan
6 - Interface Innovator
6 - Interface Innovator

Hey @masterconquero 👋

There's no explicit way of creating options via the API (even with the latest API releases to my knowledge)

There is however the`{typecast: true}` method, here's an example from a test in the airtable.js library

The documentation for your base should contain the following if you want to do further reading:

Screenshot 2022-12-06 at 14.31.56.png

goksan
6 - Interface Innovator
6 - Interface Innovator

Note that there are other potential side effects of using this, I don't know that there's any documentation for the conversions that are attempted

Screenshot 2022-12-06 at 14.34.40.png

If you want to play it extra safe - consider exclusively writing to your select fields when using the typecast parameter.

Hi, thank you for the reply. This unfortunately does not help me because I want to create a new record with the new ice cream flavour where as if I understand correctly, `{typecast: true}`will just allow me to add new flavours but not add them to the list of allowed flavours. Do you know if I could add my use case as a potential future feature to the airtable team?

masterconquero
4 - Data Explorer
4 - Data Explorer

Hey I found out where I can add this as a feature request.

Unless I've misunderstood this should satisfy your requirement.

It allows you to create a new record with the new ice cream flavour, it is also added to the list of allowed flavours thereafter.

masterconquero
4 - Data Explorer
4 - Data Explorer

Well yes, for the part of the problem I stated it does but it does not solve my overall problem. Eventually I will also have another table called sales where I want to track which flavours have the highest sales. In this table as well, I want to only add the same flavours. So what I was looking for was a single source which can add flavours to all the tables. However with this process I will add flavours for each process which updates each table. In case one of the process fails for some reason, I will have to go and check manually. I do not want to give away the checking which Airtable does to make sure this is part of the allowed list of flavours everytime I write a new row.

Given that you want to use the list of flavor choices across multiple tables, I suggest using a new linked table listing the flavors instead of a single select. 

masterconquero
4 - Data Explorer
4 - Data Explorer

@Kevin_Kuo I will take a look at this.

masterconquero
4 - Data Explorer
4 - Data Explorer

@kuovonne For now I will stick with the solution @goksan provided and mark that as the accepted solution. When I get to the multi table set up. I will take a look at this again.

In the mean time I noticed that all the multiple select options were being given the light blue colour, when I was adding the options by hand there is an option to add different colours. Is there some field which can be added so the colours for the fields are random? This is not needed for my solution, just a wish.