Mail to maximum 4 clients

Hello,
I am using a client's API, and they want to send an invitation email to their colleagues when the user enters their email addresses using the API. They want us to be able to send an email to up to 4 people. I have managed to do this when I send an email with all 4 people whose information is filled out correctly. However, if there is incorrect information for any of the 4 people, it does not work. I am unable to send an email for just 1, 2, or 3 individuals; I am required to fill out information for all 4. Could you please help me?

Sorry way too little information to give you any specific help. But in general I would say you need to create a transformer that checks the validity of all of your emails then adds only those that are valid to your API. You then need to figure out how to send a variable number of addresses to your email API.

All email APIs that I am aware of use an array to specify the receiving email addresses which can be any length.

Hello, thank you for your response, i send you a loom link, for the comprehension of the problem :

That was very clear, thanks.

Your array is hard coded and so has no way of knowing that one or more of your emails are not filled in. You need to create a transformer that will dynamically create the array you send to your API. It will look something like this:

Call the javascript transformer called trMakeUsersToInvite

let usersToInvite = []

if ({{email1.value}} != '') {
   usersToInvite.push({role: {{select1.value}}, email: {{email1.value}} })
}

if ({{email2.value}} != '') {
   usersToInvite.push({role: {{select2.value}}, email: {{email2.value}} })
}

... Etc. .. 

return {usersToInvite: usersToInvite}

The in your REST query's Body you put {{trMakeUsersToInvite.value}}

That should get you working

2 Likes