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.

3 comments:

  1. I am getting the error "Couldn't resolve user {the email I provided}."

    ReplyDelete
    Replies
    1. In order to share a site with external users, we need to enable the external sharing feature. By default, it is set to "Only people in your organization." However, please note that only Global Administrators or SharePoint Administrators in Microsoft 365 have the authority to change the sharing settings for a site. Please refer below link to change the sharing settings for a site: https://learn.microsoft.com/en-us/sharepoint/change-external-sharing-site

      Delete