Select to view content in your preferred language

Survey 123 Connect - Captures a Photo but how do I embed it in an Email

940
7
01-07-2024 09:14 AM
JeffSilberberg
Frequent Contributor

So I have a Survey 123 that captures a photo and stores it as an attachment based on the JSON being passed into my WebHook and the Data displayed in the Item Details data Panel. 

The portion of the Webhook for the attachment gives the URL and the Name (See Below). So I thought I could take the URL plus the Name and put it into an <img> src="......." </img> to embed the image into an email MIME format message.  When I went to test the resulting URL in my browser it failed with a token-required message.    If I add a ?token=......  to the URL am I not creating a security issue? 

TIA -- 

sprintf("<img alt=\"Documenting Photo\" height=\"128\" width=\"128\" src=\"%s/%s\" />", $bodyJSON['feature']['attributes']['Photo'][0]['url'], ['feature']['attachments']['Photo'][0]['name']);

 

JeffSilberberg_0-1704647378625.png

 

 

 

 

 

 

            [attachments] => Array
                (
                    [Photo] => Array
                        (
                            [0] => Array
                                (
                                    [globalId] => {..........}
                                    [parentGlobalId] => {..........}
                                    [name] => Photo-20240106-160729.jpg
                                    [contentType] => image/jpeg
                                    [keywords] => Photo
                                    [size] => 86358
                                    [id] => 6
                                    [url] => https://services2.arcgis.com/.............../arcgis/rest/services/......../FeatureServer/0/17/attachments/6
                                )

                        )

                )

 

0 Kudos
7 Replies
abureaux
MVP Frequent Contributor

Do you have the image part working? If so, this seems like a security question rather than a "how to" question.

I am not a security expert, so I will point you to this article which discusses securing HTTP actions.

0 Kudos
JeffSilberberg
Frequent Contributor

 

Thank you for the link it's an interesting read.  But it really has nothing to do with accessing the Photo attachment from a Survey 123 entry.   

0 Kudos
abureaux
MVP Frequent Contributor

So are you still looking for how to attach the photo? If so, try this:

Option A: Attach image in body of email

1. Flow Trigger of When a survey response is submitted

abureaux_0-1704739357734.png

2. Initialize variable (Name is up to you. Type is String)

abureaux_1-1704739365198.png

3. HTTP. For the URI, specify the Image URL (as you pointed out in your initial post). This will automatically create an Apply to each because all image questions are technically arrays. (As such, this works best with a single image).

Method: GET
URI: Image URL

abureaux_3-1704739587555.png

Queries: token / Portal Info Token (see below)

abureaux_2-1704739512006.png

5. Compose. Choose Expression and enter (If you renamed your HTTP step, then that will need to be reflected below):
concat('<img src="',dataUri(body('HTTP')),'"alt=""/>')

6. Set variable to the Outputs of the previous Compose

abureaux_4-1704740145381.png

7. Use that Variable in your email body

abureaux_5-1704740201659.png

 

Option B: Attach one or more images to email

1. Flow Trigger of When a survey response is submitted

abureaux_0-1704739357734.png

2. Initialize variable (Name is up to you. Type is Array)

3. HTTP.Same as previous example

4***. Set variable. Choose your array. Enter this Value.

[
{
"Name": items('Apply_to_each')?['name'],
"ContentBytes": body('HTTP')
}
]

Name is the name of the image. You can use the Name value in S123, or come up with your own custom name.
ContentBytes is the Body of the previous HTTP step.

5. In the Send an email step, click on Show advanced options > click Switch to input entire array > choose your array variable

abureaux_6-1704740668015.png

*** So this part is variable. You can attach a single image this way. If you want to attach multiple images, you can. But, you need use Append to array variable and add that into its own Apply to each, which complicates things. It is doable though.

0 Kudos
JeffSilberberg
Frequent Contributor

 

Interesting.  So this Power Automate process would attach the Image to the email? 

I am not using this but rather I am developing a PHP script to receive the Webhook, Generate the email with the Image embedded not attached, and then execute some code to populate/update other Feature Layers and a SQL database. 

So all the other parts work, It's just this Photo headache. But when I get a chance I will translate this into PHP and try the Attach instead of Embedding the Image. 

 

 

 

 

 

0 Kudos
abureaux
MVP Frequent Contributor

Yes. I actually provide both versions: Either embed the image into the email or attach the image(s) to the email (as an attachment). I tested both and they both work.

0 Kudos
JeffSilberberg
Frequent Contributor

Thank You.

I have been pulled into another "More important" issue.  So it may be a week or more before I can get back to this, but I will close the loop with you when I have more information. 

 

0 Kudos
abureaux
MVP Frequent Contributor

Sounds good! Best of luck.

0 Kudos