3

I tried the below code with GetMyProperties in a SharePoint Hosted app and it works, but the following code gives me a bad request

    url = appweburl +
    "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\user'"
     method: "GET",
     headers: { "Accept": "application/json; odata=verbose" },
     success: successHandler,
     error: errorHandler

But it gives me a bad request... Please help me

  • found it, it was "domain\\user" error... missed the extra backslash – Betsen Oct 29 '13 at 18:45
  • Add this as an answer! – Robert Kaucher Mar 8 '14 at 21:01
5

It is recommended to utilize encodeURIComponent in order to encode accountName for GetPropertiesFor method.

function getUserProfile(accountName,success,error)
{
   var siteUrl = _spPageContextInfo.siteAbsoluteUrl;  
   $.ajax({
        url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            success(data.d);
        },
        error: error
    });
}

//Usage
var accountName = 'i:0#.f|membership|username@tenant.onmicrosoft.com'; 
getUserProfile(accountName,function(entity){
   console.log(JSON.stringify(entity));     
},
function(data){
   console.log(JSON.stringify(data));     
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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