SpRestLib

SpRestLib

  • Download
  • Get Started
  • API Documentation
  • SharePoint Guides
  • GitHub

›Recent Posts

Recent Posts

  • Uploading a file to a SharePoint library using JavaScript
  • Downloading a file from SharePoint library using JavaScript and REST API
  • Converting SharePoint 2010 API column names to SharePoint 2013 API column names
  • SharePoint List Unique Permissions REST Query
  • Adding a User to SharePoint Group Using REST with SpRestLib
  • Creating SharePoint jQuery People-Picker with SpRestLib
  • Creating SharePoint List Columns Using REST
  • Uploading a file to a SharePoint library using REST

Adding a User to SharePoint Group Using REST with SpRestLib

September 3, 2018

Brent Ely

Adding a User to an existing SharePoint Group can be done using a SpRestLib REST call in just a few lines of code.


Example

// HowTo: Get the GroupID if you dont already have it
sprLib.site().groups({ title:'Dev Site Members' })
.then(arrResults => { console.log('Group Id = '+arrResults[0].Id) })

// EX: Add a User to Group
sprLib.rest({
    url: '/sites/dev/_api/web/sitegroups(123)/users',
    type: 'POST',
    data: JSON.stringify({ "__metadata":{"type":"SP.User"}, "LoginName":"domain\\userID" })
})
.then(arrResults => console.log(arrResults))
.catch(strErr => console.error(strErr));

Notes

The value for LoginName can vary wildly across Microsoft SP implementations/tenants.

Here are a few examples of possible values - usually only one of these will work.

  • "domain\brent_ely"
  • "domain\123456"
  • "i:0#.w|domain\123456"
  • "i:0#.w|domain\brent_ely"
Tweet
Recent Posts
  • Example
  • Notes
SpRestLib
Docs
Getting Started with SpRestLibSharePoint API ReferenceSharePoint Development GuidesAbout JavaScript Promises
Community
FacebookTwitterPinterestYouTube Channel
More
GitHub IssuesGitHub ProjectSpRestLib on Stack OverflowSite Icons
Copyright © 2019 Brent Ely