Work with user profiles in SharePoint
Learn about common programming tasks for working with user profiles in SharePoint.
APIs for working with user profiles in SharePoint
User profiles and user profile properties provide information about SharePoint users. SharePoint provides the following APIs that you can use to programmatically work with user profiles:
Client object models for managed code
.NET client object model
Silverlight client object model
Mobile client object model
JavaScript object model
Representational State Transfer (REST) service
Server object model
As a best practice in SharePoint development, use client APIs when you can. Client APIs include the .NET client object model, the JavaScript object model, and the REST service. For more information about the APIs in SharePoint and when to use them, see Choose the right API set in SharePoint.
Note
Not all functionality that you find in the Microsoft.Office.Server.UserProfiles assembly is available from client APIs. For example, you have to use the server object model to create or change user profiles because they're read-only from client APIs (except the user profile picture). Also, there's no client-side access to some namespaces, such as Microsoft.Office.Server.Audience , Microsoft.Office.Server.ReputationModel , or Microsoft.Office.Server.SocialData . To see what's supported functionality for the client APIs, see Microsoft.SharePoint.Client.Social and Microsoft.SharePoint.Client.UserProfiles .
Each API includes a manager object that you use to perform core profile-related tasks. Table 1 shows the manager and other key objects (or REST resources) in the APIs and the class library (or access point) where you can find them.
Note
The Silverlight and mobile client object models are not included in Table 1 or Table 2 because they provide the same core functionality as the .NET client object model and use the same signatures. The Silverlight client object model is defined in Microsoft.SharePoint.Client.UserProfiles.Silverlight.dll, and the mobile client object model is defined in Microsoft.SharePoint.Client.UserProfiles.Phone.dll.
Table 1. SharePoint APIs used for working with user profiles programmatically
Common programming tasks for working with user profiles in SharePoint
Table 2 shows common programming tasks for working with user profiles and the members that you use to perform them. Members are from the .NET client object model (CSOM), JavaScript object model (JSOM), REST service, and server object model (SSOM).
Table 2. API for common programming tasks for working with user profiles
Task | Members |
---|---|
Create an instance of a manager object in the context of the current user | CSOM: PeopleManager JSOM: PeopleManager REST: GET http://<siteUri>/_api/SP.UserProfiles.PeopleManager SSOM: UserProfileManager (overloaded) or PeopleManager |
Change the current user's profile picture | CSOM: SetMyProfilePicture JSOM: setMyProfilePicture REST: POST http://<siteUri>/_api/SP.UserProfiles.PeopleManager/SetMyProfilePicture and pass the picture parameter in the request body SSOM: UserProfile [PropertyConstants.PictureUrl].Value or SetMyProfilePicture |
Get the current user's properties | CSOM: GetMyProperties JSOM: getMyProperties REST: GET http://<siteUri>/_api/SP.UserProfiles.PeopleManager/GetMyProperties (or get some basic user properties from /_api/social.feed/my or /_api/social.following/my ) SSOM: GetUserProfile |
Get a particular user's properties | CSOM: GetPropertiesFor JSOM: getPropertiesFor REST: GET http://<siteUri>/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\\user' SSOM: GetUserProfile (overloaded) or GetPropertiesFor |
Get the user profile properties for a particular user | CSOM: GetUserProfilePropertiesFor JSOM: getUserProfilePropertiesFor REST: not implemented. Call GetPropertiesFor and then get the user profile properties from the UserProfileProperties property of the returned PersonProperties object. SSOM: GetEnumerator |
Get a specific user profile property for a user | CSOM: GetUserProfilePropertyFor JSOM: getUserProfilePropertyFor REST: GET http://<siteUri>/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='PreferredName')?@v='domain\\user' SSOM: UserProfile (overloaded) and specify the property name in the indexer |
Get a user profile | CSOM: GetUserProfile (returns the client-side user profile for the current user only) JSOM: getUserProfile (returns the client-side user profile for the current user only) REST: POST http://<siteUri>/_api/SP.UserProfiles.ProfileLoader.GetProfileLoader/GetUserProfile (returns the client-side user profile for the current user only) SSOM: GetUserProfile (overloaded) |
Find out whether a user account exists | CSOM: not implemented JSOM: not implemented REST: not implemented SSOM: UserExists |
Create or change user profiles and user profile properties and attributes (Client APIs can change the profile picture. See the "Change the user's profile picture" task in this table.) |
CSOM: not implemented JSOM: not implemented REST: not implemented SSOM: multiple???see How to: Work with user profiles and organization profiles by using the server object model in SharePoint |
Delete a user profile | CSOM: not implemented JSOM: not implemented REST: not implemented SSOM: RemoveProfile or RemoveUserProfile (overloaded) |
Provision a user's personal site | CSOM: CreatePersonalSiteEnque (overloaded) JSOM: createPersonalSiteEnque (overloaded) REST: POST http://<siteUri>/_api/SP.UserProfiles.ProfileLoader.GetProfileLoader/GetUserProfile/CreatePersonalSiteEnqueue SSOM: CreatePersonalSite() (overloaded) |
Provision one or more users' personal sites Available for My Site Host administrators on SharePoint Online only |
CSOM: CreatePersonalSiteEnqueueBulk JSOM: createPersonalSiteEnqueueBulk REST: POST https://<domain>-admin.sharepoint.com/_api/SP.UserProfiles.ProfileLoader.GetProfileLoader/CreatePersonalSiteEnqueueBulk and pass a string array of email addresses for the emailIDs parameter (200 characters maximum) in the request body (example: {'emailIDs':['usera@contoso.onmicrosoft.com','userb@contoso.onmicrosoft.com']} ). SSOM: CreatePersonalSiteEnqueueBulk |
New objects for users and user properties in SharePoint
SharePoint includes the following new objects that represent users and user properties:
The SocialActor object and the SocialActorInfo object represent users (and documents, sites, and tasks) for feed and following activities.
A new client-side UserProfile object that provides methods you can use to create a personal site for the current user. However, it does not contain all the user properties that the server-side UserProfile object contains.
The PersonProperties object contains general user properties and its UserProfileProperties property contains user profile properties. PersonProperties is the primary API for accessing user properties from client-side code.
Note
Server object model versions are the SPSocialActor object and the PersonProperties object.