0


I need to retrieve User Profile information by REST.
I am using this code:

$(document).ready(function(){
    var requestUri = "http://mySite/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='myDom\user123'";
    var requestHeaders = { "accept": "application/json;odata=verbose" };
    $.ajax({
        url: requestUri,
        contentType: "application/json;odata=verbose",
        headers: requestHeaders,
        success: function (data) {
            console.log(data.d);
        },
        error: function (msg) {
            console.log(msg);
        }
    });
});

I always have a NULL result (on success).
What am I doing wrong?

1 Answer 1

1

The account name should be encodeURIComponent.

var accountname = 'myDom\user123';
var requestUri = "http://mySite/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'";

The same task can be done in a different way as below

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);
    }
});

Source

2
  • If i need all the properties? I need a properties to see if the user is active on user profile
    – Nk SP
    Commented Nov 10, 2014 at 13:42
  • Check the source link i provided. I has a list of available properties. Commented Nov 10, 2014 at 13:43

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.