In my last post SharePoint 2013: Working with User Profiles & JavaScript CSOM we saw how to get SharePoint UserProfile Properties using the JavaScript Client Object Model. In this post lets have a look at how to get them using the REST API. Here is a quick reference for the REST API endpoints.
(List of All User Properties and UserProfile Properties at the end of the post)
1) Get all properties of current user:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties2) Get single property of current user:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties/PictureUrlOR
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl
3) Get Multiple Properties for the current user:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl,AccountName4) Get all properties of Specific User:
For Office 365/SharePoint Online:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|vardhaman@siteurl.onmicrosoft.com'
For SharePoint 2013 On-Premises:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\username'
5) Get Specific UserProfile Property of Specific User:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='i:0%23.f|membership|vardhaman@siteurl.onmicrosoft.com'
For SharePoint 2013 On-Premises:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='domain\username'
6) Get Multiple UserProfile Properties for Specific User:
Update (01/06/2016): Since the time I wrote this post, REST API batching has been implemented in SharePoint Online. As a result, we can make multiple REST requests to the GetUserProfilePropertiesFor function in a single REST call. This way, we can get Multiple custom/OOB UserProfile Properties for a Specific User without making multiple calls.
Here is my post on it:
SharePoint Online: Get UserProfile Properties with REST API Batching
Original Post Continues:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertiesFor
_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertiesFor
As far as my research is concerned, this method is NOT supported in the REST API. The call to this method returns the following error:
"The method GetUserProfilePropertiesFor cannot be invoked as its parameter propertiesForUser is not supported."
If anybody finds any additional information on this, then I would love to update my blog on it. Here is my code for executing the above method:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var theData = { | |
"propertiesForUser": { | |
"__metadata": { "type": "SP.UserProfiles.UserProfilePropertiesForUser" }, | |
"accountName": "i:0#.f|membership|vardhaman@tsunami684.onmicrosoft.com", | |
"propertyNames": ["PreferredName", "Department"] | |
} | |
}; | |
var requestHeaders = { | |
"Accept": "application/json;odata=verbose", | |
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val() | |
}; | |
jQuery.ajax({ | |
url:_spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertiesFor", | |
type:"POST", | |
data: JSON.stringify(theData), | |
contentType : "application/json;odata=verbose", | |
headers: requestHeaders, | |
success:function(data){ | |
console.log(data); | |
}, | |
error:function(jqxr,errorCode,errorThrown){ | |
console.log(jqxr.responseText); | |
} | |
}); |
-------
List of User Properties (Use the GetPropertiesFor function for these):
AccountNameDirectReports
DisplayName
ExtendedManagers
ExtendedReports
IsFollowed
LatestPost
Peers
PersonalUrl
PictureUrl"
Title
UserProfileProperties
UserUrl
List of User Profile Properties (Use the GetUserProfilePropertyFor function for these):
AboutMe
SPS-LastKeywordAdded
AccountName
SPS-Locale
ADGuid
SPS-Location
Assistant
SPS-MasterAccountName
CellPhone
SPS-MemberOf
Department
SPS-MUILanguages
EduExternalSyncState
SPS-MySiteUpgrade
EduOAuthTokenProviders
SPS-O15FirstRunExperience
EduPersonalSiteState
SPS-ObjectExists
EduUserRole
SPS-OWAUrl
Fax
SPS-PastProjects
FirstName
SPS-Peers
HomePhone
SPS-PersonalSiteCapabilities
LastName
SPS-PersonalSiteInstantiationState
Manager
SPS-PhoneticDisplayName
Office
SPS-PhoneticFirstName
PersonalSpace
SPS-PhoneticLastName
PictureURL
SPS-PrivacyActivity
PreferredName
SPS-PrivacyPeople
PublicSiteRedirect
SPS-ProxyAddresses
QuickLinks
SPS-RegionalSettings-FollowWeb
SID
SPS-RegionalSettings-Initialized
SISUserId
SPS-ResourceAccountName
SPS-AdjustHijriDays
SPS-ResourceSID
SPS-AltCalendarType
SPS-Responsibility
SPS-Birthday
SPS-SavedAccountName
SPS-CalendarType
SPS-SavedSID
SPS-ClaimID
SPS-School
SPS-ClaimProviderID
SPS-ShowWeeks
SPS-ClaimProviderType
SPS-SipAddress
SPS-ContentLanguages
SPS-Skills
SPS-DataSource
SPS-SourceObjectDN
SPS-Department
SPS-StatusNotes
SPS-DisplayOrder
SPS-Time24
SPS-DistinguishedName
SPS-TimeZone
SPS-DontSuggestList
SPS-UserPrincipalName
SPS-Dotted-line
SPS-WorkDayEndHour
SPS-EmailOptin
SPS-WorkDayStartHour
SPS-FeedIdentifier
SPS-WorkDays
SPS-FirstDayOfWeek
Title
SPS-FirstWeekOfYear
UserName
SPS-HashTags
UserProfile_GUID
SPS-HireDate
WebSite
SPS-Interests
WorkEmail
SPS-JobTitle
WorkPhone
SPS-LastColleagueAdded