1

i use this query to get User properties

/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=%27SP%5Catish%27

In response i get a UserProfileProperties object which shows all the information in key value format.

I do not want all these properties. Is it possible to select specific properties from this UserProfileProperties object?

1 Answer 1

1

yes you can use it like this for single property:

/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v,propertyName='LastName')?@v='i:0%23.f|membership|[email protected]'

for multiple properties use it like this:

var theData = {
 "propertiesForUser": {
    "__metadata": { "type": "SP.UserProfiles.UserProfilePropertiesForUser" }, 
    "accountName": "i:0#.f|membership|[email protected]",
    "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);
    }
});
6
  • try it..but It shows The parameter name propertyName is not valid. error Oct 14, 2016 at 8:57
  • is it Office 365 or OnPrem ? Oct 14, 2016 at 9:01
  • it is OnPrem... Oct 14, 2016 at 9:03
  • /_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='domain\username' - try like this. Also make sure , you are entering correct property name. Oct 14, 2016 at 9:08
  • this also shows same error Oct 14, 2016 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.