In this post I will share you the steps to add user/users to SharePoint (online) group using REST API.

sharepoint-icon-x128

Prerequisites

You need the below to follow the tutorial/steps

  • To call REST API I have used Power Automate. You can use Postman or VS code or anything else as per your choice.
  • SharePoint Online Management Shell for SPO PowerShell

Implementation

To add a user in SharePoint you need to send a HTTP POST request to the SharePoint user collection library. The request looks as below

Add user SharePoint using REST API
REST API call from Power Automate

As you can see in the above screenshot we are sending a POST request with user login details in the body. For SharePoint online the login name should be in the below format.
LoginName > i:0#.f|membership|[email protected]
However it depends upon your organization settings, so make sure you are providing the correct LoginName parameter value.

Rest of the details are explained below

Request Parameters

Site Address : The SharePoint site URL where you want to add the user using the REST API call

Method : As this is a item creation request, POST is used.

Uri: The endpoint for adding the user to SharePoint.
For this example I have used _api/web/sitegroups(<group id>)/users , this is helpful to add user to any particular group. However if you wish to add user directly and not through any group then you can use the following endpoint as well; _api/web/siteusers

Headers: Just to provide more information about the request body. However if you are using any other application to call the REST end point then you need to pass authentication information as well.

Body:

{ 
'__metadata': { 'type': 'SP.User' },
'LoginName': 'i:0#.f|membership|[email protected]' 
}

That’s all for the request, if you call the API successfully then the users will add in the SharePoint site group as expected.

Add user to SharePoint site using REST API from Power Automate
Successful API call

Well that’s all I have on how add users to SharePoint using REST API. I hope you now have some idea on how to proceed. However if you want to learn more, check this Microsoft document

https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-rest-reference/dn531432(v=office.15)?redirectedfrom=MSDN#about-the-request-examples-in-this-article

Please Help us Grow!

I hope you have found this article helpful. If you are happy with the document, please use the below links when you buy something from Amazon to help us grow.

How this works?

Amazon affiliate program gives a small (%)share of price to the referrers, so feel free to buy anything.
Below are some Amazon affiliate links, if you open amazon application/website using these links and buy something, (it can be one of the below items or anything of your choice) Then Amazon will give us a little percentage(%) of the money you spend on Amazon. To know more check this document.

Amazon Affiliate Links

$350-Best Student laptop
Amazon In, Amazon US

$600-Work laptop
Amazon In, Amazon US

$989– High performance
Amazon In, Amazon US

Headset – $15.99
Amazon In, Amazon US

Lightspeed Mouse – $39
Amazon In, Amazon US

Keyboard – $29
Amazon In, Amazon US

The Psychology of Money
Amazon In, Amazon

Atomic Habits:
Amazon In, Amazon

Find Balance and Purpose in Life
Amazon In, Amazon

$30, Smart Watch for Smart you
Amazon In, Amazon US, Amazon UK

Work comfortably with $110
Amazon In, Amazon US, Amazon UK

Exercise at home
Amazon In, Amazon US, Amazon UK

More Ways to Help

Thank you
For your Contribution


Newbietechie.com
Author @ramizmollahmd

About Ramiz

Ramiz is a professional working in an MNC as a business and technology consultant for quite a few years now. Ramiz is proficient in various Microsoft tools and technologies. He is a tech enthusiast and an active blogger. Ramiz spends his free time playing games or watching movies. He writes blogs to share his knowledge with the world and to make it a better place to live.


Leave a Comment