Thursday, October 3, 2019

Integrate Azure Logic Apps with SharePoint Site Designs

SharePoint Site Designs is becoming more and more popular among Office 365 specialists. I've seen consultants and IT-pros connecting Site Designs with Hub Sites to create consistent environments as well as triggering Microsoft Flow from Site Designs during site collection creation to enhance the default templates offered by Microsoft. In this blog post, I want to present a further scenario which covers the integration of Azure Logic Apps to Site Designs.

Perhaps you have already taken advantage of Azure Logic Apps to build complex workflows and now you want to reuse your Logic App during the process of site creation in SharePoint or you just want to run these Logic Apps in existing SharePoint site collections. Another scenario is that you might just want to use Azure Logic Apps instead of Flow in your SharePoint site collections. Due to Flow's licensing model or limitations. The first good news is that you don't need to migrate your Azure Logic App to Microsoft Flow. The second good news is that there aren't bad news 😊 Maybe a little bit of configuration, but no bad news. Let's get started on the deep dive.


Topics:

1. The jumping-off point
2. Let's go back to the drawing board - Understanding the Flow Architecture
3. Set up the Azure Logic App
4. Set up the SharePoint Site Design


1. The jumping-off point

SharePoint Site Scripts already supports integration to Microsoft Flow (What are you talking about? I'm here for the Logic App stuff 😊) Well, the triggerFlow action plays the key role on this integration since this action supports requests to Microsoft Flow as well as to Azure Logic Apps. Just to refresh your memory, here is what the action looks like:

{
    "$schema": "schema.json",
        "actions": [
            {
                "verb": "triggerFlow",
                // Flow's trigger URL.
                "url": "",
                // Flow's name.
                "name": "",
                // An option set of parameters to pass into the Flow.
                "parameters": {
                    "event": "",
                    "product": ""
                }
            }
        ],
        "bindata": { },
        "version": 1
}

Instead of setting up the triggerFlow action with a Flow URL, you can "hack" the SharePoint Site Script entering an Azure Logic App URL. It requires your Logic App to start via http trigger. Otherwise you can't trigger the Logic App using the triggerFlow action.

Ta da... The triggerFlow action is the place where the magic happens!

2. Let's go back to the drawing board - Understanding the Flow Architecture


The picture above clarifies the Microsoft Flow architecture (The similarity to the army rank is mere coincidence 😊) Logic Apps can always do everything that Microsoft Flow can do since Flow is built on top of Logic Apps. Let's deep dive on that. Analyzing the http trigger URL of both: a Flow and a Logic App, reveals the relationship between these services:

Flow's HTTP Trigger URL

https://prod-64.westeurope.logic.azure.com:443/workflows/
a675d12d8f223658b6e641bd57f6ac19/triggers/manual/paths/invoke?
api-version=2016-06-01&
sp=/triggers/manual/run&
sv=1.0&
sig=IMP9ZIj9iIJCxAXQF-JwbRzCihJj5n1ZFPoa6jQI4JQ

Logic App's HTTP Trigger URL

https://prod-47.westeurope.logic.azure.com:443/workflows/
caa9b98eb1137c91bfa6340fd3362f2e/triggers/manual/paths/invoke?
api-version=2016-10-01&
sp=/triggers/manual/run&
sv=1.0&
sig=79tV6zQHN8GzdSL_QvF2edDb3yUk3i5WuHlGfXErbO0

Both URLs points to endpoints hosted in Azure => westeurope.logic.azure.com. If you have been playing around with Flow, you have been using Azure. Now you know that you are an Azure specialist too 😊

3. Set up the Azure Logic App

Your Azure Logic App's http trigger must fit the requirements to communicate with the Site Script's triggerFlow action. Therefore, we must set up the Request Body JSON Schema field with the JSON definition of the incoming object. The picture below shows the http trigger filled in with the correct JSON definition.


4. Set up the SharePoint Site Design

Since I've already demonstrated this topic in past blog posts, I'll shortly cover it. This step consists of creating a Site Script and a Site Design. The Site Script below has been reduced to the triggerFlow action only which has been set up with the http trigger URL of the Azure Logic App. Here is what it looks like:

{
    "$schema": "schema.json",
        "actions": [
            {
                "verb": "triggerFlow",
                "url": "https://prod-47.westeurope.logic.azure.com:443/workflows/caa9b58eb1434c91bfa6340fd3361f2e/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=79tV3zQHN8GzdSL_QvF2eFDb3ykk3i5WuHlGfXERbO0",
                "name": "Send request",
                "parameters": {
                }
            }
        ],
        "bindata": { },
        "version": 1
}

The script below demonstrates how to add a new Site Script and a new Site Design using Add-SiteScript and Add-SiteDesign. Depending on your strategy, you can connect the site design with the following site templates:

 1:    Modern site without group
 64:  Modern site with group
 68:  Communication site
 Any other value:  No template association. For instance, use the Site Design through the Site Design Panel

Here is what the script looks like:

Connect-SPOService -Url https://example-admin.sharepoint.com
# Retrieves copied script from clipboard
$script = Get-Clipboard -Raw
# Adds site script
$siteScript = Add-SPOSiteScript -Title "Logic App" -Content $script
# Adds site design
Add-SPOSiteDesign -Title "Logic App Connection" -WebTemplate 64 -SiteScripts $siteScript.Id 

Well done! Your Azure Logic App has been successfully connected to Site Designs and can now be used in SharePoint!


Summary:

The triggerFlow action is a powerful instrument in Site Designs that makes it possible to integrate Microsoft Flow as well as Azure Logic Apps. I've already tried to trigger other service endpoints without effort. In case a find a hack, I'll share it with the community!


Links:
Compare Microsoft Flow and Azure Logic Apps
Demystifying Azure Logic Apps
• http://www.spsevents.org/city/Brussels/Brussels2016/Lists/SPSSessions/Attachments/91/SPSBE2016_MsFlow_AzureLogicApps_pjcov.pdf

No comments:

Post a Comment