When I started this little project for someone, I thought it was going to be a lot easier than it ended up being. Since I tried so many different methods and they all didn't work, I'll share with you the one that did.
First, we need a survey to collect images for us. I created this simple survey called "SP_Image_Guide". Pro Tip: SharePoint's image column really only works with a single image, so we want out image question to only allow a single attachment.
Next, we need a SharePoint list. I created a new list called "SP_Image_Guide" and added a single new column: myImage. Pro Tip: When making SP list columns (and anything in SP, really), give it a simple name with no special characters or spaces first. After it has been created, then you can rename it to whatever you want.
The 'myImage' column is Type: Image'.
Now start a new flow (don't forget to turn off "New designer" in the top right). The Trigger will be when our new survey is submitted.
Create a couple String Variables.
Add 'Get attachment from URL'. This can be a little misleading at first. To do this, type 'Esri' > select your appropriate connector (ArcGIS for AGO environments, or ArcGIS Enterprise for Enterprise environments) > then add 'Get attachment from URL'.
Search for 'attachment' in the Dynamic Content, and add your attachment URL.
Even though we are only working with a single Image, all attachments in S123 are created as arrays. As such, Power Automate will automatically put our step into an Apply to Each. That's totally fine! We will be working inside this Apply to Each until I say otherwise.
Next, we need to put that attachment somewhere. I used Create File and saved it in a folder on my SP site. Pro Tip: When adding the Folder Path, don't forget to click on the "Folder" icon for easy navigation.
Dont forget that your file name needs to be unique. I added my attachments name from Survey123, but when in doubt, append utcNow()
Set you two variables. Source is the previous Create File.
Your Apply to Each is now complete. You can minimize it and continue.
Now we add Create Item to create this item in our SharePoint list. And here we can finally see why this is such an annoying operation... there is no Image question! That's okay though.
By this point, we have now saved our image somewhere and created a SharePoint item. Cool. Now, let's merge the two together. Add a 'Send an HTTP request to SharePoint'. Copy what I have below.
Site Address | Your SP Site |
Method | POST |
Uri | _api/web/lists('*SP List ID*')/items(*Create Item ID*)/validateUpdateListItem() |
Headers (Click the "Switch Headers to text mode" button just to the right of Headers) | { "Content-Type": "application/json;odata=verbose", "accept": "application/json;odata=verbose" } |
Body | {"formValues":[{"FieldName":"*SP Image Column Name*","FieldValue":"{\"type\":\"thumbnail\",\"fileName\":\"*variables('imgName')*\",\"fieldName\":\"*SP Image Column Name*\",\"serverUrl\":\"https://*your SP site name*.sharepoint.com\",\"serverRelativeUrl\":\"/sites/*Your SP Site**variables('imgPath')*\"}","HasException":false,"ErrorMessage":null}],"bNewDocumentUpdate":false,"checkInComment":null} |
Pro Tip: To get you SP List ID for the Uri, go to your SP list > Click 'Settings' in the top right > Click 'List Settings' > copy the alphanumeric code in the URL bar.
Pro Tip: The body makes more sense when you look at it in the image below. To generate the below image, I copy-pasted the body into VS Studio Code, Find and Replaced (Ctrl+H) all \" with ", and then delete the " (two total) surrounding FieldValue's curly braces. Then right-click anywhere in the window and click Format Document. The above mess is using the \ to escape the ", so it ends up looking worse than it really is.
Pro Tip: You can find the proper column names for your SP List by going to your SP List > Setting > List Settings > Scroll down to the "Columns" section > Click on a column name > look in the URL bar
That's all there is to it! Here is an overview of the full flow.
And here is a test run.