I am trying to pass data from Formidable Forms to Brevo with an API. Here is my code so far:
{ "updateEnabled": true,
"email": "[376]",
"emailBlacklisted": false,
"smsBlacklisted": false,
"attributes": {
"FIRSTNAME": "[374]",
"LASTNAME": "[375]",
"GENRE": ["[385]"]
},
"listIds": [2]
}
It works perfectly until I add in genres. The id 385 is the answers for a multiple-selection question in Formidable Forms and has the same answers as the GENRE attribute in Brevo. Formidable Forms defaults to a comma separated format but Brevo requires an array of strings. Currently, it will pass the data only if the first option in the form is selected. If anything else is selected, the other data transfers but the genre is left blank. Any ideas on how I can get it to pass all of the genre data in an array?
I tried the code listed above and I also tried the below (adding .split to help make it an array).
let selectedGenres = formData[385];
let genreArray = selectedGenres.split(',').map(item => item.trim());
let apiRequest = {
"updateEnabled": true,
"email": "[376]",
"emailBlacklisted": false,
"smsBlacklisted": false,
"attributes": {
"FIRSTNAME": "[374]",
"LASTNAME": "[375]",
"GENRE": genreArray
},
"listIds": [2]
};
2
Answers
If the form data doesn’t already have
[]
around each ID, you need to add it.i’d suggest using string.match(regex_pattern) like below:
the regex is a bit nutty, but it should handle ‘normal’ csv and odd cases like double quotes, double commas, starting with a comma and more