In this blogpost I want to show the cooperation of SharePoint Online, Microsoft Flow and Azure Runbook as a simple combination of technologies to fulfill backend processes with Office 365 SharePoint Online.
The story is quite short but for such a demo the right thing:
The user story
Let’s take a really brief example which is too simplified for a real world scenario but very good for demo scenarios of simple backend processes:
A user adds an item by giving a Firstname and a Lastname and the system builds the Fullname from it.
Manually with PnP PowerShell this would be a simple two-liner (Connect-PnPOnline + Set-PnPListItem). Therefore we use a simple Azure Runbook for this. The Azure Runbook we trigger by a Flow that is triggered by the list item creation. Of course we could establish a direct webhook in list items creation but we assume the Flow does more than just run the the Webhook (“more” we omit here for brevity as we want to focus on the cooperation of the technologies)
The SharePoint list
This is a simple list with only 3 columns (Shame on me I did not hide the standard title but in a demo …):
The Azure Runbook
Due to PnP PowerShell this is quite a simple task but one small thing is the challenge here: The Parameters.
To start a PowerShell function in a script or a runbook to be called by an APi you would start something like this:
But as we call the Runbook via Webhook, we need to provide our 3 parameters in a slightly different way.
In this script you first see how the 3 desired parameters are retrieved from an incoming JSON string provided in the body.
The rest of the script is for demonstrative reasons: I wanted to provide all three values although I retrieve the list item and therefore only would have needed the ID of the item. But this way you later see how to provide more than one value. I only retrieve the item for some output later I update it by creating the Fullname from the 2 parameters First- and Lastname. That’s it.
I don’t want to explain the details of creating a Runbook environement. Refer to the official Microsoft documention to create an Automation Account, a Runbook and add the PnP PowerShell module to it as well as your SPO credentials if you are not familiar with it. But if you do not need too complex code can fulfill your needs with PowerShell a runbook is a vaild and lightweight alternative to Webjobs or Azure Functions.
Finally we need to create a Webhook for our Runbook. Therefore click on “Webhook” having the runbook open in the same menu as “Edit” or “Publish” reside.
Then you need to provide a name and a “valid until” date. Take care to copy the Webhook Url before clicking OK as the token at the end cannot be viewed afterwards anymore. You retrieve a Url like this
https://s2events.azure-automation.net/webhooks?token=<THIS IS YOUR TOKEN>
Keep this Url, you’ll need it again in the next step.
The Microsoft Flow
To create the flow we go to our SharePoint list and choose “Flow | See your flows”.
Of course we need a connector to SharePoint Online if we do not have it already established.
After that we can create a new Flow without a template and choose as a trigger
The next step is to enter our site url and the list name. With our SharePoint Online connection the form helps us with suggestions
Next we add a simple Http Action
Finally we have to fill out the Http Action. Therefore we choose a POST method. The Url is that one we previously copied when we created our Webhook.
Header parameters we do not really need but the Body is interesting. We can enter a simple JSON object, including our three parameters
Afterwards we simply replace the “VALUE” with dynamic content and choosing the corresponding list columns. That’s it.
To test our construction we just create a new list item by entering First- and Lastname only.
After this is done we can switch to our Flow (as mentioned above) and check it’s activity.
In our case it’s already succeeded but let’s also check the detailed activity.
It seems the call was correct and the body (“Körper”) seems correct. Below we find additional information about the call but let’s also check our runbook which can tell us what happened as well.
We go to our runbook and check the jobs is fulfilled. For the last run we can see the input
We identify our body here as well.
Finally we can check our list and the result is a correctly filled “Fullname”.
Although this is only a demo scenario and very simplified it shows the cooperation between an Azure Runbook, its Webhook, a Microsoft Flow and SharePoint Online in a transparent way. Hope you enjoyed it.