Thursday, August 30, 2018

Microsoft Flow - Provision SharePoint Online Modern Sites using REST

Today i want to provide an article regarding MS Flow, first article and no clue for the next. :P

I was exchanging some questions with Doctor Flow (@sergeluca) in Twitter regarding MS Flow provision and Office 365 Groups and he provide me some great insight and help and very great step by step implementation with Azure, PnP framework and MS Flow.
Here is the article:
MICROSOFT FLOW PROVISIONING OFFICE 365 GROUPS, SHAREPOINT SITES, APPLYING PNP TEMPLATES AND WAITING FOR COMPLETION [AZURE FUNCTION, FLOW, AZURE QUEUE]
https://sergeluca.wordpress.com/2017/08/01/microsoft-flow-provisioning-sharepoint-sites-applying-pnp-templates-and-waiting-for-completion-azure-function-flow-azure-queue/
PS: If you want to learn about Office 365 Low code (MS Flow, Powerapps, PowerBI) you should definitely follow him and read his material.

Base in the provided example, i wanted to make more investigation and understand where can we really go with MS Flow, HTTP REST and Provisioning, base in the MS Flow.
PS: PnP provisioning framework is very complete and definitely should be used for provisioning and recommend by Microsoft.

Following simple Business case:
( Of course can be more complex, but here a simple PoC)

  1. Create a Powerapps Form with SharePoint List behind to save the Request.
  2. SharePoint List stores the entries and start MS Flow process of provisioning Modern Team Sites with Office 365 Groups.
  3. The MS Flow process starts and updates the SharePoint Items associated and make SharePoint HTTP request for the provisioning of the Modern Team Site (Office 365 Group)
  4. The Modern Team Site is available and associated Group base in the alias and available in Office 365.


Full Steps in Images

1. Team with Powerapp form Tab to Request Projects



2. SharePoint List where are stored data from the Form
3. MS Flow where the provisioning of the Site are made.

4. After provision of the Modern Team Site, then become avaliable.

--------------------------------------------------------------------------------------------------------------------------

For this implementation made some investigation regarding HTTP REST about provision and there were 2 type of provision i was looking about "Modern Communication Site" and "Modern Team Sites".
Here are my outputs:

1. Provision SharePoint Online Modern Communication Site 




When i was making my research, my first thought was to look in the Microsoft Documentation and found the following article that i use in my MS Flow Action and Metadata associated.

Create SharePoint Communication site using REST
https://docs.microsoft.com/en-us/sharepoint/dev/apis/communication-site-creation-rest 

Method: POST
Uri: "_api/sitepages/communicationsite/create"
Metadata:
{
  "request": {
    "__metadata": {
      "type": "SP.Publishing.CommunicationSiteCreationRequest"
    },
    "Title": "Comm Site 1",
    "Url": "https://{tenant}.sharepoint.com/sites/comm1",
    "Description": "",
      "Classification":"LBI",
      "SiteDesignId":"{Site design ID}",
    "AllowFileSharingForGuestUsers": false,
    "lcid":1033
  }

}

Implementation of the MS Flow Action "HTTP request to SharePoint" for the provisioning of the Communication Site.


This made the job.
PS:(take in consideration that some scenarios you will need to use Graph to get the Access Token by Graph and associated in the Headers)
"Get access tokens to call Microsoft Graph"
https://developer.microsoft.com/en-us/graph/docs/concepts/auth_overview

An older method was used for the provisioning "publishingsite" REST.
Important: "/_api/sitepages/publishingsite/create" with "type":"SP.Publishing.PublishingSiteCreationRequest" was the old way and most problaby not supported, should be used the following method;
Official: Create SharePoint Communication site using REST


2. Provision SharePoint Online Modern Team Sites (Office 365 Group)



As last Method, my first thought was also to look in the Microsoft Documentation but didn't found articles about, then use Search engines and found the following http Request "_api/GroupSiteManager/CreateGroupEx" that was used in my MS Flow Action and Metadata associated.

Create SharePoint Modern Team (Office 365 Group) site using REST

Method: POST
Uri: "_api/GroupSiteManager/CreateGroupEx"
Metadata:
{
"displayName": "test modernteamsite",
"alias": "testmodernteamsite",
"isPublic": true,
"optionalParams": {
"Description": "Test",
"CreationOptions": {
"results": []
}
}
}

Implementation of the MS Flow Action "HTTP request to SharePoint" for the provisioning of the Modern Team Site.
This made the job for the provisioning of Modern Team Sites. After accessing Team and join the Group the new Team Modern Site was available.




Provision Sub Site SharePoint Online Modern Team Sites





Provision of Sub Sites is more easy and more well documented "used since SP 2013" Microsoft has a very detail article regarding different SharePoint REST call that can be used for this purpose, Creating a sub Site with REST.

Method: POST
URI: "_api/web/webinfos/add"
Metadata: {
'parameters': {
'__metadata': {
'type': 'SP.WebInfoCreationInformation'
},
'Url': 'RestSubWeb',
'Title': 'RestSubWeb',
'Description': 'REST created web',
'Language': 1033,
'WebTemplate': 'sts',
'UseUniquePermissions': false
}

}

Implementation of the MS Flow Action "HTTP request to SharePoint" for the provisioning of Sub Site with Modern Team Site.

This 3 REST call can help you with the provisioning using MS Flow, but it's important to take in consideration other point such us permissions, governance and a good life cycle of all your process, Training is critical and always validate, test and validate, over and over and over.... 

Research Documentation:
PnP Sites Core
https://github.com/SharePoint/PnP-Sites-Core 
Create SharePoint Communication site using REST
https://docs.microsoft.com/en-us/sharepoint/dev/apis/communication-site-creation-rest 
Microsoft Flow Provisioning Office 365 Groups, SharePoint sites, applying PnP templates, queuing...
https://powerusers.microsoft.com/t5/Microsoft-Flow-Community-Blog/Microsoft-Flow-Provisioning-Office-365-Groups-SharePoint-sites/ba-p/61126
MICROSOFT FLOW PROVISIONING OFFICE 365 GROUPS, SHAREPOINT SITES, APPLYING PNP TEMPLATES AND WAITING FOR COMPLETION [AZURE FUNCTION, FLOW, AZURE QUEUE]
https://sergeluca.wordpress.com/2017/08/01/microsoft-flow-provisioning-sharepoint-sites-applying-pnp-templates-and-waiting-for-completion-azure-function-flow-azure-queue/
"Get access tokens to call Microsoft Graph"
https://developer.microsoft.com/en-us/graph/docs/concepts/auth_overview

Hope you like it, 

Best Regards, 
André Lage

No comments: