June 30, 2022

Invite External Users to a SharePoint Site / Add External Users to a SharePoint Group via Power Automate

Introduction

In this blog, we will demonstrate how we can programmatically add external users to a SharePoint Group without using Azure Application and User.Invite.All permission with the help of Power Automate. 

Solution

Firstly, we will create a JSON object that will contain the data that we need to add a new external user to a SharePoint Group as shown in the below image. 

Replace the highlighted content in the object below:

 {   
  "url": "https://tenantname.sharepoint.com/sites/sitename",   
  "peoplePickerInput": "[{\"Key\":\"Email Address\",\"DisplayText\":\"Email Address\",\"IsResolved\":true,\"Description\":\"Email Address\",\"EntityType\":\"\",\"EntityData\":{\"SPUserID\":\"Email Address\",\"Email\":\"Email Address\",\"IsBlocked\":\"False\",\"PrincipalType\":\"UNVALIDATED_EMAIL_ADDRESS\",\"AccountName\":\"Email Address\",\"SIPAddress\":\"Email Address\",\"IsBlockedOnODB\":\"False\"},\"MultipleMatches\":[],\"ProviderName\":\"\",\"ProviderDisplayName\":\"\"}]",   
  "roleValue": "group:GroupID",   
  "sendEmail": true,   
  "emailBody": "",   
  "includeAnonymousLinkInEmail": false,   
  "useSimplifiedRoles": true   
 }   
Set the Email Address of the external user that you want to add to the SharePoint Group.  

Set the GroupID of the SharePoint Group to which you want to add the user. 


Now that we have created the JSON string with the required data, the next step will be to add this JSON to the Request Body and send the request as shown in the below image.



In the "Send an HTTP request to SharePoint" action fill the details as per below:
 Site Address: https://tenantname.sharepoint.com/sites/sitename   
 Method: Post   
 Uri: _api/SP.Web.ShareObject   
 Headers:    
 {   
  "accept": "application/json;odata=verbose",   
  "content-type": "application/json;odata=verbose"   
 }   
 Body: Output of Compose Action   
The flow can now be tested. Once the flow instance has succeeded the invite is sent to the external user. After the external user accepts the invite, the user should be automatically redirected to the SharePoint site with the appropriate access. 

Conclusion

By using this HTTP Post Request, we can invite an external user to any SharePoint Site without any need of the Azure App and any mandatory permissions such as User.Invite.All (which requires Admin Consent). Hope this helps!

If you have any questions you can reach out our SharePoint Consulting team here.

No comments:

Post a Comment