Hi,
I'm trying to create a logic app workflow with HTTP trigger which will receive the following payload.
{
"email_body": "Hi Users,<br>Please find the files attached.",
"email_recipients": "recipients@xyz.com;",
"email_subject": "Do not reply - processed files",
"email_attachments": [{
"container_name": "bronze",
"blob_name": "rootfolder/subfolders/folium_map.html"
}, {
"container_name": "bronze",
"blob_name": "rootfolder/subfolders/stdout.txt"
}, {
"container_name": "bronze",
"blob_name": "rootfolder/subfolders/stderr.txt"
}
]
}
Upon receiving such request, I need to send an email containing the attachments depending of however many is defined in the "email_attachments" array. I will need to lookup the content of such blob from my data lake. Here's my code:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "attachments",
"value": {
"ContentBytes": "@{body('Read_blob_content')?['content']}",
"Name": "@{body('Read_blob_content')?['blob_name']}"
}
},
"runAfter": {
"Read_blob_content": [
"SUCCEEDED"
]
},
"type": "AppendToArrayVariable"
},
"Read_blob_content": {
"inputs": {
"parameters": {
"blobName": "@items('For_each')?['items(''For_each'')']?['blob_name']",
"containerName": "@items('For_each')?['items(''For_each'')']?['container_name']"
},
"serviceProviderConfiguration": {
"connectionName": "AzureBlob-4",
"operationId": "readBlob",
"serviceProviderId": "/serviceProviders/AzureBlob"
}
},
"type": "ServiceProvider"
}
},
"foreach": "@triggerBody()?['email_attachments']",
"runAfter": {
"Initialize_variable_-_attachments": [
"SUCCEEDED"
]
},
"runtimeConfiguration": {
"concurrency": {
"repetitions": 1
}
},
"type": "Foreach"
},
"Initialize_variable_-_attachments": {
"inputs": {
"variables": [
{
"name": "attachments",
"type": "array"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Response": {
"inputs": {
"body": "@concat('Email sent to ',triggerBody()?['email_recipients'], ' with the subject of \"',triggerBody()?['email_subject'],'\"')",
"headers": {
"Content-Type": "application/json"
},
"statusCode": 200
},
"kind": "http",
"runAfter": {
"Send_an_email_from_a_shared_mailbox_(V2)": [
"Succeeded"
]
},
"type": "Response"
},
"Send_an_email_from_a_shared_mailbox_(V2)": {
"inputs": {
"body": {
"Attachments": "@variables('attachments')",
"Body": "<p>@{triggerBody()?['email_body']}</p>",
"Importance": "Normal",
"MailboxAddress": "sender@xyz.com",
"Subject": "@triggerBody()?['email_subject']",
"To": "@triggerBody()?['email_recipients']"
},
"host": {
"connection": {
"referenceName": "office365"
}
},
"method": "post",
"path": "/v2/SharedMailbox/Mail"
},
"runAfter": {
"For_each": [
"SUCCEEDED"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"email_attachments": {
"items": {
"properties": {
"blob_name": {
"type": "string"
},
"container_name": {
"type": "string"
}
},
"required": [
"container_name",
"blob_name"
],
"type": "object"
},
"type": "array"
},
"email_body": {
"type": "string"
},
"email_recipients": {
"type": "string"
},
"email_subject": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"kind": "Stateful"
}
When I called the workflow, it ended with the following error:
InvalidTemplate
Unable to process template language expressions for action 'For_each' at line '0' and column '0': 'The template language expression 'triggerBody()?['email_attachments']' cannot be evaluated because property 'email_attachments' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.
I tried using array(triggerBody()?['email_attachments']) in the "Select An Output From Previous Steps" field on the "For each" action, but that doesn't help either.
Can anyone help shedding a light of how I can achieve that please?
Thanks in advance.