SP.User object

Represents a user in Microsoft SharePoint Foundation.

Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.User()

Members

The User object has the following members.

Constructor

The User object has the following constructor.

Constructor

Description

User

Initializes a new instance of the SP.User object.

Methods

The User object has the following methods.

Method

Description

initPropertiesFromJson

update

Updates the user with changes that have been made to the user properties.

Properties

The User object has the following properties.

Property

Description

email

This property is not available in SharePoint Online. Gets or sets the email address of the user.

groups

Gets the collection of groups of which the user is a member.

isSiteAdmin

Gets or sets a Boolean value that specifies whether the user is a site collection administrator.

userId

Gets the information of the user that contains the user's name identifier and the issuer of the user's name identifier.

Example

The following example creates an input button on an application page that adds the current user to the visitors group on the current website.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

var user;
var visitorsGroup;

function runCode() {

     var clientContext = new SP.ClientContext();
     var groupCollection = clientContext.get_web().get_siteGroups();
     // Get the visitors group, assuming its ID is 4.
     visitorsGroup = groupCollection.getById(4);
     user = clientContext.get_web().get_currentUser();
     var userCollection = visitorsGroup.get_users();
     userCollection.addUser(user);

     clientContext.load(user);
     clientContext.load(visitorsGroup);
     clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

function onQuerySucceeded() {
    alert(user.get_title() + " added to group " + visitorsGroup.get_title());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>

REST resource endpoint

See User resource for more information.

Endpoint URI structure

http://<sitecollection>/<site>/_api/web/sitegroups(groupid)/users(loginname)

HTTP requests

This resource supports the following HTTP commands:

DELETE syntax

DELETE http://<sitecollection>/<site>/_api/web/sitegroups(groupid)/users(loginname)

MERGE syntax

MERGE http://<sitecollection>/<site>/_api/web/sitegroups(groupid)/users(loginname)

POST syntax

POST http://<sitecollection>/<site>/_api/web/sitegroups(groupid)/users(loginname)

PUT syntax

PUT http://<sitecollection>/<site>/_api/web/sitegroups(groupid)/users(loginname)