Saturday, September 28, 2019

Adding multiple accounts to a SP group using MS Flow and REST API

Here are the steps to include multiple accounts into a SharePoint group using Microsoft Flow and REST API.

1 - Create a SharePoint list with the accounts that you would like to include the SP group.



2 - Create a MS Flow workflow with the following steps:

A) Include a "Get Items" step to retrieve all the accounts from the SP list containing the accounts,



B) Include a "Send an HTTP request to SharePoint". From the Microsoft URL https://msdn.microsoft.com/en-us/library/office/dn531432.aspx we see that the javascript REST call to add a user to a group is the following:

executor.executeAsync({
  url: “<app web url>/_api/SP.AppContextSite(@target)/web    /sitegroups(7)/users    ?@target='<host web url>'”,
  method: “POST”,
  body: “{ ‘__metadata’: { ‘type’: ‘SP.User’ }, ‘LoginName’:’i:0#.w|domain\\user’ }”,
  headers: {
    “accept”: “application/json; odata=verbose”,
    “content-type”: “application/json; odata=verbose”
  },
  success: successHandler,
  error: errorHandler
});




3 - Run the workflow. When these steps are executed, the system will include the users to the SP group.

No comments:

Post a Comment

About Me

My photo
Toronto, Ontario, Canada
MBA, M.Sc. & MCP