Is there and example of using Power Automate to send an email using image captured from Survey123?

1631
6
Jump to solution
08-20-2020 08:19 AM
EricHalstead
New Contributor

We capture a lot of photos with Survey123 and I would like to include those photos into emails that I send to various people to help them better understand what the issue is that we are capturing.  The emails I send are generated with Power Automate and the Survey123 connector.  As of yet i have not had any success in figuring out how to use Power Automate to attache images to the emails.  Any assistance would be greatly appreciated.

1 Solution

Accepted Solutions
IsmaelChivite
Esri Frequent Contributor

The workflow is not particularly straight-forward.

If you are using a secure survey:

  • I suggest you make your photo question required in your survey. This ensures you always get a photo.
  • In Automate, create a new flow against your survey.
  • Go into the Survey123 website and click on the Settings tab of your survey, then switch to the Webhooks section, turn on portal info in the payload and save the webhook.

  • The portalinfo group includes the token of the logged in user in the survey123 form. You will need this to successfully download the survey photo before you can attach it to the email in Automate.
  • In your flow, add an HTTP action after the Survey123 module. This will help you download the photo. Populate the URL using the Dynamic Content's 'feature attachments photo URL' value.  Then, in the Queries section make sure you add a new query using token for the key and @{triggerOutputs()?['body/portalInfo/token']} for the value

  • Now add a new action to send the email. You can use the feature attachments photo name value from Dynamic Content to populate the name of the attachment. For the attachment content, select the output of the HTTP module.

Test and go.

If you are using a public survey, the instructions are slightly different.

If using a public survey, you do not need to worry about the token at all, so you do not need to add the portalInfo group into the payload, or add the token as a query to the HTTP module.

However, you need to make sure the permissions in the field_worker view are set to allow anonymous users to query ALL features, otherwise you will get an attachment in the email with no content.

Note: Since Survey123 allows you to capture multiple photos with a single image question, the webhook payload includes an array of attachments. For this reason, Automate will automatically create an 'Apply to Each' component in your workflow. This is not shown in the screenshots above but you will see it in Automate when you go through the steps. You may want to limit the number of attachments to be sent to 1 to keep things simple.

Note: The instructions above ONLY work if you publish the survey with 3.10 or newer.  If you use the Survey123 field app to submit data, make sure the version is 3.10 or newer too.

View solution in original post

6 Replies
IsmaelChivite
Esri Frequent Contributor

The workflow is not particularly straight-forward.

If you are using a secure survey:

  • I suggest you make your photo question required in your survey. This ensures you always get a photo.
  • In Automate, create a new flow against your survey.
  • Go into the Survey123 website and click on the Settings tab of your survey, then switch to the Webhooks section, turn on portal info in the payload and save the webhook.

  • The portalinfo group includes the token of the logged in user in the survey123 form. You will need this to successfully download the survey photo before you can attach it to the email in Automate.
  • In your flow, add an HTTP action after the Survey123 module. This will help you download the photo. Populate the URL using the Dynamic Content's 'feature attachments photo URL' value.  Then, in the Queries section make sure you add a new query using token for the key and @{triggerOutputs()?['body/portalInfo/token']} for the value

  • Now add a new action to send the email. You can use the feature attachments photo name value from Dynamic Content to populate the name of the attachment. For the attachment content, select the output of the HTTP module.

Test and go.

If you are using a public survey, the instructions are slightly different.

If using a public survey, you do not need to worry about the token at all, so you do not need to add the portalInfo group into the payload, or add the token as a query to the HTTP module.

However, you need to make sure the permissions in the field_worker view are set to allow anonymous users to query ALL features, otherwise you will get an attachment in the email with no content.

Note: Since Survey123 allows you to capture multiple photos with a single image question, the webhook payload includes an array of attachments. For this reason, Automate will automatically create an 'Apply to Each' component in your workflow. This is not shown in the screenshots above but you will see it in Automate when you go through the steps. You may want to limit the number of attachments to be sent to 1 to keep things simple.

Note: The instructions above ONLY work if you publish the survey with 3.10 or newer.  If you use the Survey123 field app to submit data, make sure the version is 3.10 or newer too.

View solution in original post

EricHalstead
New Contributor

Ismael,

Thanks for getting back to me so quickly. I’ll see if I can get this working!

0 Kudos
SusanMathai
New Contributor II

Thanks a lot Ismael, the above post was very helpful! You are the best as always!!!!!!

0 Kudos
MackenzieCarter
New Contributor II

Hi Ismael, thanks for the example! I followed the example that was shown here but I still get the message, "Token Required." Is there something else that I could possibly be missing?

Thanks! 

0 Kudos
daveostrander
Occasional Contributor II

Hi Ismael,

To combat the no attachments uploaded issue in Power Automate, I do a conditional check using the empty function to check if attachments exist. 

CheckForAttachmentsConditional_PowerAutomateExpression_20210107.PNG

If that results in true then I do the email with attachments or add attachments to another feature service, etc... If false, send without.

 

IfSurveyHasAttachmentsConditional_20210107.PNG

Maybe this would be useful.

-dave o.

0 Kudos
KarlBrixZinglersen
New Contributor II

@IsmaelChivite 

In our setup of Microsoft Automate the HTTP Action seems to be a PREMIUM feature to which we don't have access to. Are there other options?

Karl