Dec 06, 2022 06:03 AM
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. 🙂
Solved! Go to Solution.
Dec 06, 2022 06:32 AM
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:
Dec 06, 2022 06:32 AM
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:
Dec 06, 2022 06:39 AM
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
If you want to play it extra safe - consider exclusively writing to your select fields when using the typecast parameter.
Dec 07, 2022 12:39 AM
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?
Dec 07, 2022 01:19 AM
Hey I found out where I can add this as a feature request.
Dec 07, 2022 01:39 AM
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.
Dec 07, 2022 04:19 AM
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.
Dec 07, 2022 04:47 AM
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.
Dec 07, 2022 08:11 AM
@Kevin_Kuo I will take a look at this.
Dec 09, 2022 12:11 AM
@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.