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

4431
9
Jump to solution
08-20-2020 08:19 AM
EricHalstead
New Contributor II

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 Notable 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

9 Replies
IsmaelChivite
Esri Notable 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.

EricHalstead
New Contributor II

Ismael,

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

0 Kudos
SusanMathai
New Contributor III

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! 

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.

DeonLengton
Esri Contributor

Hi @IsmaelChivite 

>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.

Regarding the comment above. Would it not be possible to expose the token that the Survey123 Connector is using when it performs the GetOwnedSurveyList operation? In our case we need to create a Feature Report from the submitted survey but obviously that requires a token...

We have worked around it for now by doing a GenerateToken call but it seems to be double work if the Survey123 connector already has a valid token?

Would love to hear your inputs on the matter...

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

LaxmiKondapalli
New Contributor

Hello Karl,

Any luck how to get it working without Premium?

We do have a organizational policy limitation.

 

Any help.

 

Thanks,

0 Kudos
LindaSlattery
Occasional Contributor

@IsmaelChivite , I have up to 3 images in my survey and I can get the images to show up in the body of the email, but if all three images aren't there (i.e., only one image was uploaded), the email does not send. I am using a table and getting the image to appear by referencing each URL (<img src="@{items('Apply_to_each')?['url']}">) in a table column. Any idea why it fails if all three are not there? I would have thought it would have just been a blank cell in the table.

0 Kudos