Customize SharePoint Modern Pages using Microsoft Flow

Did you know that you can use Microsoft Flow to work with modern pages in Communication or Team Sites in SharePoint? Well, you can.

There are no specific actions for modern pages in Microsoft Flow. However, you can combine actions for list items, files and SharePoint HTTP requests with the SharePoint REST endpoints or API to do a lot of things.


The REST endpoints for modern pages are unfortunately not that well documented by Microsoft (at least not when this post was written). But by analyzing the web traffic a bit its quite easy to see how Microsoft uses these endpoints in the SharePoint web interface.

In the following example I will use a form in Microsoft Forms to collect information and based on responses create new modern pages, based on a common ”template” that I have defined. I want to collect user input in a very structured way and then create a nice looking modern page that can be viewed, promoted and used to communicate with a much larger group.

Microsoft Forms to Modern Page using Flow.

In the picture above I have embedded the form on a modern page to make the user experience a bit better.

I could collect and present the same information using a simple SharePoint list, or even Excel spreadsheet. But- let’s be honest, a SharePoint list is not quite as appealing as reading a nice formatted modern page. The modern pages also offer commenting and features to promote the information in a much better way.

Using a modern page, I can also merge several text fields in the form to a larger chunk of rich text when presented for the end user.

I need four things to get this working.

• A form in Microsoft Forms.
• A custom page content type.
• A page template.
• A Flow to automate the whole process.

The Form

The form is probably the easiest part, once you know what information you want to collect from the user.

I will not explain how Microsoft Forms work in this post. You will figure that out in two minutes (or maybe one).

I create a form with 8 different input fields.

Microsoft Forms
Click here to see the complete form.

The Custom Page Content Type

I want to be able to both present the information entered as page properties and in rich text on the modern page. The properties will allow my end users to filter, sort and find relevant pages using a list webpart.

I create a custom content type based on the standard site page content type for modern pages. Add a couple of fields, matching some of those I defined in my form.

Note that I only add 3 fields, not all the 8 fields I defined in the form. I will add the rest as rich text on the page, or as the title

Custom content type based on Site Page for modern pages

The Page Template

There’s no concept for templates for modern pages in Communication Sites or Team Sites (yet) in SharePoint Online. But I would still like some sort of template-ish thing that I can start from. I want to be able to place a couple of page property webparts as well as define where I want to place my rich text.

Since we don’t have decent template management I will create a page in my library, customize it and simply let my Flow start with a copy of this ”template”. It’s the closest to a template I can get to right now.

I will of course make sure I use my custom content type for my template page and add the page property webpart for the properties/fields I want to display on the page in such a way.

Modern pages template page

Click the image to see a larger version of it.

The Flow

This is where it all comes together. The Flow will be triggered by the incoming Microsoft Forms response. It will copy the template page and customize the new page with both metadata/properties and rich text content. The Flow will finally publish the new modern page and make it available for my end users.

Below I will go through all the steps and actions in the Flow. If you prefer a complete picture with all the actions in the Flow click here.

Step 1. The Flow will be triggered by a new form response. I also declare a variable for the page name. I have chosen a simple static label together with a number (response id) in this example to make it simple but it could of course also include text from the response, like the title (after some sanity check and clean-up).


Step 2. Copy the page I use as a template. I use a HTTP Request action and make a request using the the CopyTo REST endpoint. I use the PageName variable I initialized in the previous step to set the file name of the new file.


Step 3. The next action, Get file metadata action will help me get the item id of the new file, my new modern page. I need the item id later on when updating the page further.


Step 4. The Update file properties action updates the properties/fields of the page. I utilize the metadata fields in the custom content type and populate them with information from the form response.


Step 5. HTTP Request to check out the file so I can make changes to the page content. I use the CheckOutPage REST endpoint, _api/sitepages/pages({id})/CheckOutPage .


Step 6. HTTP Request to save the rich text content. This is the trickiest part in this Flow since I need to make sure I post the proper blob, together with a number of other properties, such as the title. I don’t really want to put together this blob manually. Instead I use the developer toolbar and copy the blob from when I save the template page. I then replace some of the labels with dynamic content in Flow. Dynamic content from the Form response.


Chrome Developer Toolbar

Use the SavePageAsDraft REST endpoint to save the modern page content, _api/sitepages/pages({id})/SavePageAsDraft .

BONUS! If you want even more flexible you can bring up the current content/blob from the template page, parse it and replace static labels with dynamic content. Doing so will take away the hazard of managing the large blob. It will require a few more steps in parsing the blob but you will on the other hand be able to change the page template more easily without having to update the Flow and the blob each time. The response from the CheckOutPage endpoint used in a previous step return the blob, that can be parsed with some magic.

Step 7. Finally, check in and publish the finished page using the Publish REST endpoint and the now familiar HTTP Request to SharePoint action, _api/sitepages/pages({id})/Publish .


Download a picture of the complete Flow.

This is a simplified example on how we can use the SharePoint – Send an HTTP request to SharePoint action together with Microsoft’s REST endpoints/API to work with modern pages. In a critical Flow I would recommend you improve the error handling, cleaning up the user input, parse the response given by the HTTP requests and add notifications when things go wrong. You may wan to parse the long text from the Form entries to manage page breaks and similar since it will cause problems with the HTTP requests in my simple example.

I’m not sure why the documentation regarding these REST endpoints is lacking. Could be that Microsoft haven’t gotten around to it yet. Could also be that they still are making changes to it. This is a risk you should consider.


Leave a Reply