Webhook returns an array, how to parse it into multiple rows?

Hello guys !

Im ne here an I can’t wait to know more about airtable, but right now I can’t get what I need and that’s frustrating : i’ve got a webhook that returns me an array of values.
I want each value to be distributed to a unique row as “title”, but Airtable takes the array and puts it in one cell of one row. Not very useful !
Can I use a formula to distrubute values ?
Thank you,
Diane

You would either need to write your own custom JavaScript to process the array, or you could use a low-code automation tool like Integromat which can receive your webhook & automatically iterate through the array for you.

The necessary script is pretty simple. If you include a “Run a script” action in your Automation, add the array as an input config variable named arr that is the array from your webhook (left side of the screen), and the script would be:

// Change the names in quotes if necessary
let tableName = "Table 6"
let fieldName = "Name"

// Do not edit below this line
let {arr} = input.config()
let table = base.getTable(tableName)

let values = arr.split(",").map(v => {
    return {
        fields: {
            [fieldName]: v
        }
    }
})

while (values.length > 0) {
    await table.createRecordsAsync(values.slice(0, 50))
    values = values.slice(50)
}

That’s very helpful.
What changes in the code are needed, if the array is only in one cell of a line and the other values of the line should be duplicated into the new lines. Do you know what I mean?

Shopping List A | {Apples, Cheese}
Shopping List B | {Banana, Chocolate}

becomes
Shopping List A | Apples
Shopping List A | Cheese
Shopping List B | Banana
Shopping List B | Chocolate

add all the field values you want inserted to the new record as input variables the same as you did for the array.

let {arr, otherValue1, otherValue2, otherValue3} = input.config()

let values = arr.split(",").map(v => {
    return {
        fields: {
            [fieldName]: v,
            "Name of Other Field 1": otherValue1,
            "Name of Other Field 2": otherValue2,
            "Name of Other Field 3": otherValue3
        }
    }
})

The exact format you supply to the other fields will depend on the field type they’re getting inserted into.