SharePoint 2013: Get UserProfile Properties with REST API

1) Get all properties of current user:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties


2) Get single property of current user:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties/PictureUrl
OR
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,AccountName



4) Get all properties of Specific User:


For Office 365/SharePoint Online:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='user name'

For SharePoint 2013 On-Premise:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\username'



5) Get Specific UserProfile Property of Specific User:


For Office 365/SharePoint Online:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='user name'


For SharePoint 2013 On-Premise:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='domain\username'



var theData = {
 "propertiesForUser": {
"__metadata": { "type": "SP.UserProfiles.UserProfilePropertiesForUser" }, 
"accountName": "user name",
"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);
}
});

more info: http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html

Comments

Popular posts from this blog

IRM and the Object Model

This content database has a schema version which is not supported in this farm

Activate and Deactivate Feature through PowerShell