A recent chat with a customer who was looking for a solution to check modern SharePoint pages for broken links got me thinking ?
I wondered whether this could be achieved using the Power Platform (specifically Power Automate). Fast forward a few days and I had a working solution ?
This post is all about the solution I created and how you can use it too!
- Flow – ‘Check Broken Links’ (Checks for broken links and creates items in the list below).
- SharePoint List – ‘Broken Links’ (Used to store a list of pages that have broken links along with the links that are flagged as broken).
- Flow – ‘Broken Link validation’ (Sends adaptive cards to page authors allowing them to edit/update the page and flag the links as validated).
Note – The solution can handle SharePoint links and external web links.
How it works (High level)
- Flow (‘Check Broken Links’ runs when pages are created or modified in the Site Pages library.
- Verifies that the page is published by checking the version number. We only check for broken links when the author has published the page. This way we can capture all possible links in case they are editing it multiple times in draft and adding additional links.
- Retrieves the page content using the SharePoint REST API (Send HTTP request to SharePoint action).
- Converts the page content (returned as HTML) to plain text.
- Extracts possible links by splitting the text.
- Checks if the link is a SharePoint link or a web link.
- Sends a HTTP request to the link (using the SharePoint action if it is a SharePoint link or standard HTTP action for a web link).
- Appends the link to an array IF the HTTP call fails.
- Creates/or updates an item in the Broken Links’ list.
- Flow (‘Broken link validation’) runs when items are created/modified in the Broken Links list.
- Gets the page details (Id of the page is stored in the Broken Links list).
- Sends an adaptive card that requires a response to the page author.
- The user checks the list that are flagged in the adaptive card and uses the button provided to edit/update the page.
- Once the page has been updated, the user clicks the ‘Done’ button, the flow resumes.
- The status column in the Broken Links list is updated to ‘Validation Complete’
- Future edits to the page will restart the above process.
The solution in action
This is what the solution looks like in action:
- Creating a page with some broken links.
- Item gets created in the Broken Links list.
- Adaptive card is sent to the page author.
- User clicks ‘Done’ after updating the page and correcting any potential broken links.
- Adaptive card displays an update message and the status of the item in the Broken Links list is updating to ‘Validation Complete’.
Deploying the solution
So how do I deploy it?? I hear you ask. Simply follow the steps below to deploy.
The deployment steps assume a good level of knowledge with the PnP PowerShell module and Power Automate.
- Download all the neccessary files from here – https://aka.ms/spobrokenlinks
- Apply the provided PnP template (‘brokenlinkslist.xml’) to the site you wish to deploy the solution to. This will create the Broken Links list. The template was extracted from a Communication Site so it may display a warning message if you are applying this on non comms site (you can ignore this warning as we are only creating a list).
- Import both of the flows into your environment using the zip files provided – ‘CheckBrokenLinksFlow.zip’ and ‘BrokenLinkValidationFlow.zip’.
- Update the data connections with valid connections in your environment.
- Edit the ‘Check Broken Links’ flow.
- Update the Site Address in the trigger to the site in which you want to check for broken links. The Broken Links list must reside in this site.
- Update the values for the following variables:
SharePointTenantName: Name of your SharePoint tenant (excluding onmicrosoft.com e.g. contoso
SharePointTenantURL: URL to the root site in your SharePoint tenant e.g. https://contoso.sharepoint.com
SiteURL: Same URL used in the trigger (the site you want to check for broken links) e.g. https://contoso.sharepoint.com/sites/thelanding
- Save the flow.
- Edit the ‘Broken link validation’ flow.
- Update the Site Address in the trigger to the same URL used in the ‘Check Broken Links’ flow.
- Update the values for the following variables:
SiteURL: Same URL used in the trigger (the site where the Broken Links list resides).
The solution should now be deployed and ready for use. To test it, simple create a page with some broken links and wait for the flows to run and the adaptive card to come through ?
Currently the solution does not take into account links that have redirects configured where 302/303 status codes are returned. These may be flagged as broken links and the page author will need to determine if they work before validating the page.
The solution requires a premium license for Power Automate as it leverages the HTTP connector. As this is not initiated directly by a user, there is no need to license all users. Either a single license for the creator of the flow would be enough or you could use the ‘Per flow’ license type.
As always, I would really appreciate your feedback on this solution and how it could be improved.