MS Flow to grab photos in Survey123 and add them to a sql report

3859
17
04-24-2019 08:02 AM
JevitaWebster
New Contributor III

i'm using MS Flow to grab data from a Survey in Survey123, but the survey has photos. Can i use MS Flow to grab these photos and add them to the SQL report?

Tags (1)
0 Kudos
17 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Richard,

There have not been any updates regarding Survey123 Connector/Attachment interactions in Flow.

RichardHughes2
Occasional Contributor III

Okay thanks for the response... I was able to get a prototype flow together to grab photos an put into a template by following the steps in your flow.  I was surprised how relatively user friendly Flow is.  I think I will start incorporating it into more of my projects.

0 Kudos
StevenBowden
New Contributor III

Hi James Tedrick‌,

Do you have to use a "When HTTP request is received" as the first step in the process or can a Survey123 "When a survey response is submitted" be used as the trigger for the process so that you could have a flow that looked somthing like this to save the attachment

Regards

Steve

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Steven,

You do not necessarily have to use 'When an HTTP request is received', but it may make the process easier for the branch of your workflow that works with attachments.  The alternative would be to insert an HTTP request that generates a token, or have a long-lived token embedded in the flow.

0 Kudos
StevenBowden
New Contributor III

Thanks James Tedrick‌,

I am trying to replicate the process now using the "When an HTTP request is received". I have created the webook in the Survey123 Survey using the process that Tom Ruff‌ outlines in this thread MS Flow Webhook - Error (TrustFailure) for creating the webhook.  However when I enter the Queries parameters they don't seem to be accessible from the http request.

For example I have to manually enter json for the f parameter

If I add @triggerBody()?['f'] as in the sample code, it defaults to html and not json.  The same is happening with the objectIds with @{triggerBody()?['objectid']} and the token with @triggerBody()?['token']  No values seemed to be passed through.

When you view the code it looks the same as the sample code

My test

From the sample code

If I hard code the values for f, objectIds and the the token through the whole process it works.  So it must be something that I am doing wrong in the initial stage that I can't get the values for those parameters.

Any idea where I am going wrong?

I have also tried to import the sample json zip file that is attached here so that I can view how it is presented in Flow, but it fails to import into Flow.  Any ideas on why that might be as well?  Flow doesn't give any specific error message.

Regards

Steve

JamesTedrick
Esri Esteemed Contributor

Hi Steve,

A couple of things:

- I would expect hardcoded f:json key/values.  You always want to process this in JSON

- What is triggering the 'When an HTTP request is received'?  If Survey123, you aren't accessing the objected or other parameters correctly.  Take a look at my response in https://community.esri.com/thread/238790-format-of-event-data-sent-in-webhook to get some guidance on that - by far the easiest way to get this correct is to feed MS Flow a sample payload from a test submission.

0 Kudos
StevenBowden
New Contributor III

Hi James Tedrick,

I am trying to use MS Flow to save survey123 attachments to a OneDrive folder.  To try and understand and get the process working I am trying to follow the sample json file using the same feature service as listed in the file.  I am just trying to return the attachment for objectID 1 from that feature service.

When I get to the "Get Attachment" step it doesn't seem to be retrieving the attachment.  The attachment appears on the e-mail with the correct image name and extension but the file size is only 1kb, it its correct file size (it is also not viewable because it has nothing in the file).

Here is what I have in the "Get Attachment"

The get attachment code view

And here is the code view of the "Send an email"

Any ideas on what I am missing to get the actual data in the attachment?

Regards

Steve

0 Kudos
StevenBowden
New Contributor III

I worked out what my issue was, I was hard coding the objectID in the "Query Attachments" step but but then using "@{triggerBody()?['objectid']}" in the "Get Attachment" URI instead of the hardcoded objectID from the first step.

So now that I have the process working, hopefully I can adapt it to work with my feature layer.