Hi everybody,
i'am trying to get user properties (UserUrl, PictureUrl) using REST API "GetUserProfilePropertiesFor", but it doesn't work. Please anybody provide a "work"-example! Thanks a lot!
The examples I got from
next page (see 6. Get Multiple UserProfile Properties for Specific User).
I tried also another simple way:
var x = "i:0#.w|sp20130\demo";
jQuery.ajax({
url: _spPageContextInfo.webServerRelativeUrl + "/_api/sp.userprofiles.peoplemanager/getuserprofilepropertyfor(accountame=@v, propertyname='PictureURL')?@v='"+x+"'",
type: "GET",
headers: { "accept": "application/json;odata=verbose" },
success: function (data) {
var result = data.d;
console.log(data.d);
},
error: function (err) {
alert(JSON.stringify(err));
}
});Every time I receive back a error - "Bad request".
At this moment I have only one idea - it is a wrong url (problem with encoding of login name).
#########################
UPDATE! SOLUTION:
var accountName = "sp20130\\demo";
jQuery.ajax({
url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
console.log(data.d);
var pictureUrl = data.d.PictureUrl;
var userUrl = data.d.UserUrl;
...
},
error: function (data) {
console.log(JSON.stringify(data));
}
});