I'm looking for:

MS Flow and Azure: Creating Parent and Sub sites


The Assignment

Recently we were asked by a client to develop a MS Flow that creates a sub site when users enter a new item into a SharePoint list. What we found was there’s no simple, out of the box way to have the new sub site inherit the top navigation of the parent site. As a result, we needed to create an Azure Function to preform this function. 

I was tasked with developing the Azure Function and calling it from the MS Flow. This assignment seemed fairly straightforward at the beginning – follow along with some pretty detailed tutorials and bada-boom, you are done. This couldn’t have been farther from the truth.

The tutorials I used are listed below, along with the specific code for inheriting a top navigation.


Creating an Azure Function

Registering the Azure Function with Azure Active Directory

Calling CSOM from the Azure Function

Call an Azure Function from Microsoft Flow

Code for Inheriting Top Navigation

dynamic data = await req.Content.ReadAsAsync();

string webUrl = data?.webUrl.ToString() ?? "";

using (var ctx = await csomHelper.GetClientContext(webUrl))


var web = ctx.Web;

ctx.Load(web, w => w.Navigation);


web.Navigation.UseShared = true;



Lessons Learned

Adding to my false sense of confidence, creating the Azure Function went off without a hitch. I was able to follow along with the tutorial without any issues, and before I knew it I had created an Azure Function. It is important to note that when you are creating your Function App, you will want to opt out of Application Insights. If you don’t, an Application Insight will automatically be built for your Function App. This is a billable service, so be prepared to pay if you forget this step!

After creating your Azure Function, you’ll need to register it with the Azure Active Directory. This is where the process got frustrating. The first thing to note is that the instructions are for users who operate Windows 10. If you are using an older version of Windows, you will not be able to use the PowerShell commands for creating the Certificate. Instead, you will have to revert to MakeCert commands.

The second, even more maddening issue is the quirkiness of the document editor that is used to edit the app registration manifest. The author of the tutorial goes so far as to calling the editor evil. I couldn’t agree with him more.

Not only does the editor throw out mysterious errors, but further research proves that their meanings don’t match their corresponding  titles. Don’t edit the manifest in the editor! Instead, download it, edit it in your text editor, and upload it back into the manifest editor. Then there’s the mysterious “keyValueMustBeNull” error. If you get this, simply create a new GUID and that should resolve the issue.

After navigating through all that madness, I was lured back into a feeling of confidence. Setting up the Azure Function to call CSOM went smoothly. There was one small step missing in the tutorial though: When creating the csomHelper.csx file, in addition to the changes noted by the tutorial author, make sure to plug in your Function Name in the certPath. I also recommend copying the code from the gist at the top of the blog, as it is slightly different from the code in the blog.

The roller coaster ride continued as I moved on to calling an Azure Function from MS Flow. I was not able to create a custom connector that worked successfully. During the “Prepare Security Configuration” step, my drop down did not show “API Key” as an option. I created the connector two different ways: Once by choosing “None” in the drop down, which did not give me a place to enter the API Key; And once by leaving the option blank, which did allow me to enter the API Key. Both resulted in the following error upon running the flow: “Unable to match incoming request to an operation.” I finally scrapped the idea of using a custom connector. Instead, I set up an HTTP call in the MS Flow using the API Key in the query parameters.

All in all, there were many great lessons learned. Hopefully, these observations help you to avoid all the headaches and frustration I had to endure.

Looking for a new job? We work with some of the biggest names in tech, and we’re hiring! Check out our open jobs and make your next career move with Planet.

| | |