Hello there! I’m trying to send an email with attachments using a webhook. The problem is that I don’t know how to make my scenario capable of processing N number of attachments depending on how many arrive through the webhook.
In order to provide a more specific answer, a bit more context would be needed. However, here are a few hints that may point you in the right direction
Let’s assume that you have a scenario that starts with a webhook and ends with an Email module.
Further, let’s assume that you are sending your attachments in the data payload through the webhook. The data may have a form of a JSON, for example as follows:
{
"attachments": [
{
"name": "file1.png",
"data": "binarydata1"
},
{
"name": "file2.png",
"data": "binarydata2"
}
]
}
The Email module expects the attachments as an array of collections, where each collection has two mandatory parameters: “data” and “fileName”. Let’s construct a scenario that will produce this:
- In the webhook module, make sure that you select “No” in the “JSON pass-through option”. You may need to toggle the “Show advanced settings” switch to see this option. You don’t need to define any data structure for validation.
- Next, connect an Iterator module after the webhook and select the array that you want to iterate. In case of the data structure mentioned above, this would be “attachments[ ]”. Make sure that the “Map” toggle is turned on.
Important note: In order to map the data from the webhook, you need to run the hook once and therefore load it with data.
-
Next, connect an Array aggregator module right after the Iterator. We will configure it later.
-
Attach the Email module after the Array aggregator.
- Now, let’s go back to the Array aggregator. Click on the module in the scenario to display its properties and:
- Select the Iterator as the Source Module.
- Select “Email - Send an Email: Attachments” as the Target structure type. This option will be automatically available because you already have an Email module connected in your scenario.
- Now let’s map the data: Click into the “File name” text box and select the “name” parameter of the Flow Control - Iterator module as the value. Next, click into the “Data” text box and select the “data” parameter of the Flow Control - Iterator module as the value.
- We’re done, click OK.
- Finally, we need to map the newly created array of attachments in the Email module:
- Click on the Email module in the scenario editor to display its properties.
- Find the “Attachments” section and turn on the “Map” toggle.
- Click into the empty text box right underneath it and select the “Array[ ]” parameter of the Flow Control - array aggregator module as its value.
- Click OK to store the module settings.
When you run the scenario now and send the payload to your webhook, the attachments will be added to the email