Reputation: 397
I have a logic app that connects to Ms Forms and sends the result as an email. The user can upload files to Ms Forms. I don't know how many files the user will upload (could be zero) and I don't know the extension of any of these files. How can I add these files as an attachment in the email sent by logic apps? I'm using this connector to MsForms. https://learn.microsoft.com/en-us/connectors/microsoftforms/
Upvotes: 0
Views: 735
Reputation: 8234
Here is one of the workaround that you can try.
After using the trigger and the Get response details
connector to add the attachments I used a Compose
Connector in order to get the files that the person uploaded through MS Forms.
Compose Expression:
json(body('Get_response_details_2')?['r13237ad0c60f42989d7ea61d8fee6482'])
Then I'm using a For_each
loop to retrieve the files from the previous step compose connector. In the following step I'm using One drive's Get file content
Connector. As the each file will be saved with a unique Id I used to same to retrieve the file content and passed the same to Send the email
.
Here is the code view of my Logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@json(body('Get_response_details_2')?['r13237ad0c60f42989d7ea61d8fee6482'])",
"runAfter": {
"Get_response_details_2": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each_2": {
"actions": {
"Get_file_content_2": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['onedriveforbusiness']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(item()?['id']))}/content"
},
"runAfter": {},
"type": "ApiConnection"
},
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Attachments": [
{
"ContentBytes": "@{base64(body('Get_file_content_2'))}",
"Name": "@{item()?['id']}"
}
],
"Body": "<p>My Files as Attachment</p>",
"Subject": "Sample Flow",
"To": "[email protected]"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"runAfter": {
"Get_file_content_2": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"foreach": "@outputs('Compose')",
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_response_details_2": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['microsoftforms']['connectionId']"
}
},
"method": "get",
"path": "/formapi/api/forms('@{encodeURIComponent('v4j5cvGGr0GRqy180BHbR8k7o6rhlmJKk_S4R3vq7DZUQjM1VU5ONE1SRTNXVkI2N0pJTFVQM1gzMS4u')}')/responses",
"queries": {
"response_id": "@triggerBody()?['resourceData']?['responseId']"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_new_response_is_submitted": {
"inputs": {
"body": {
"eventType": "responseAdded",
"notificationUrl": "@{listCallbackUrl()}",
"source": "ms-connector"
},
"host": {
"connection": {
"name": "@parameters('$connections')['microsoftforms']['connectionId']"
}
},
"path": "/formapi/api/forms/@{encodeURIComponent('v4j5cvGGr0GRqy180BHbR8k7o6rhlmJKk_S4R3vq7DZUQjM1VU5ONE1SRTNXVkI2N0pJTFVQM1gzMS4u')}/webhooks"
},
"splitOn": "@triggerBody()?['value']",
"type": "ApiConnectionWebhook"
}
}
},
"parameters": {
"$connections": {
"value": {
"microsoftforms": {
"connectionId": "/subscriptions/<Your Subscription Id>/resourceGroups/<Your Resource group>/providers/Microsoft.Web/connections/microsoftforms",
"connectionName": "microsoftforms",
"id": "/subscriptions/b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f/providers/Microsoft.Web/locations/northcentralus/managedApis/microsoftforms"
},
"office365": {
"connectionId": "/subscriptions/<Your Subscription Id>/resourceGroups/<Your Resource group>/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/<Your Subscription Id>/providers/Microsoft.Web/locations/northcentralus/managedApis/office365"
},
"onedriveforbusiness": {
"connectionId": "/subscriptions/<Your Subscription Id>/resourceGroups/<Your Resource group>/providers/Microsoft.Web/connections/onedriveforbusiness",
"connectionName": "onedriveforbusiness",
"id": "/subscriptions/<Your Subscription Id>/providers/Microsoft.Web/locations/northcentralus/managedApis/onedriveforbusiness"
}
}
}
}
}
Note:- This causes the flow to have multiple emails (i.e., The number of files that the person has uploaded).
To have a single time to be triggered One workaround is to save all these links in one array variable and send the same to the email else you can also follow How to send only one email with multiple attachments.
Upvotes: 1