Expose SharePoint Data to the Web with HTTP API

Off the back of my Power Platform Quiz concept where I first used the HTTP API, I have built a solution that in real-time will dynamically serve up files hosted on SharePoint, also using the HTTP API in Power Automate! I first learned about this possibility whilst in discussion with Paul at TachyTelic. This is a working proof of concept and I would love to get your feedback.

Imagine that you create documents that need to be served up to the public via your website. You might have version control on these and you might want approval. Quite often the file would be saved to a traditional server or onto a SharePoint document library and then comes the time of publishing. You get in contact with your web team, you send them a copy of the document and they publish the file to the website for you. What happens next? You spot a typo and you need to edit the file and have the Web Team republish that file via the corporate content management system. How much time would you spend on this process each time?

What if there was another way?

SharePoint

I have chosen to save my files in a SharePoint document library, in a specially configured site, enabled for external sharing to Anyone. I have two additional columns, a SharingLink which is generated automatically via a Cloud Flow and a Description which is based on the approvers comments. In order to allow SharePoint to create links to all external users, you need to ask your SharePoint adminstrator to enable the Anyone setting on your chosen site. I would suspect that by default your OOTB sites will have default sharing setting set to lowest possible.

SharePoint External Sharing options
The Anyone External Sharing Permission in SharePoint Admin
SharePoint Document Library with files set up with a sharing link to anyone with the link
The SharePoint Document Library with additional columns

The Cloud Flows

The first Cloud Flow is triggered when a file is created in the ExternalFiles folder of the ExternalFiles SharePoint site. I chose a particular folder to reduce the risk of files being saved there by accident. Human error is always a possibility, especially when automation comes in to play. In order to reduce that risk further, I have an approval step in the Flow. A manager is asked to approve the file going live online and upon doing so, a SharingLink is generated as well as the comments saved to the File Description Metadata. If they reject the file upload, the original file owner is notified via Email and can upload the file again if they chose to do so.

When a file is created, send for approval and either create a link or notify file owner of rejection via email

The second flow serves up the HTML to the browser session. It is based on the HTTP trigger API which is a premium feature. It will generate a unique URL for you to call in order to trigger the action. Once called by the embedded IFrame (I am not a web developer) it runs the gets files action. I then perform a filter array on the results so that files without a shared link are removed (i.e. those without an approval), and then I use a select action to create the rows of the HTML table using the following expression:

concat('<tr><td>','<a href="',item()?['SharingLink'],'">',item()?['{Name}'],'</a></td><td>',item()?['Desc'],'</td><td>',formatdatetime(item()?['Created'],'dd/MM/yyyy hh:mm'),'</td></tr>')

I then return a response which includes the complete HTML table and this is displayed on my page dynamically. If a file is uploaded it will not show on the site until it has been approved and a link generated.

Cloud flow with approval for file sharing
HTTP API Flow which queries the External Files Folder, filters the results, creates the rows of a table and returns HTML back to the browser

The reponse action includes an expression to join the array elements of the select action to return a string of HTML.

Joining the rows of the HTML table and completing the HTML response.

The HTML IFrame

What you are seeing below is a list of files available on my SharePoint Document Library. As I have a premium trial it will only be live for another 30 days but for now you can click on the links and serve up files stored on my O365 Tenant. If I was a business I could be uploading files to this SharePoint document library regularly and simply forget about the requirement to speak with my Web Team every time I need a file uploaded to our Website. This is completely dynamic, remove a file, it’s gone, add a file, it’s there immediately for the next visitor, update a file and the link will display the latest version.

Let me know what you think below. Is this something you or your business could make use of? This is a proof of concept so please make sure you speak to your own development teams when it comes to adapting the above but please let me know how you get on.

Share