I am attempting to retrieve some profile properties for the current user, and am having a hard time with the profile picture Url specifically. Version is Sharepoint Foundation 2013.
When I open the Url from the following:
requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/SiteUserInfoList/Items(" + userid + ")?$select=Title,Picture";
I get the following xml:
<id>Web/SiteUserInfoList/Items(userid)</id>
<category term="SP.Data.UserInfoItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="Web/SiteUserInfoList/Items(userid)" />
<title />
<updated>2016-03-09T17:03:37Z</updated>
<author><name /></author>
<content type="application/xml">
<m:properties>
<d:Title>User Full Name</d:Title>
<d:Picture m:type="SP.FieldUrlValue">
<d:Description>https:domain/images/username.png</d:Description>
<d:Url>https:domain/images/username.png</d:Url>
</d:Picture>
</m:properties>
</content>
And I'm attempting to use the properties returned in this function:
function onSuccess(data, request){
var fullName = data.d.Title;
var profilePic = data.d.Picture;
$(".userName").append(fullName);
$("#profileImage").attr("src", profilePic);
}
I am able to return the Title property no problem, but I had no success getting the picture url. I was able to work around it with the following changes, but it seems a little open to potential issues:
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/SiteUserInfoList/Items(" + userid + ")/FieldValuesAsText?$select=Title,Picture";
var profilePic = data.d.Picture.split(',')[0];
This returned both the Url and Description properties in a string separated by ", " which could be split to give me the value I needed. Is there a way I can drill down to select the Picture Url property directly, or is this a limitation of Rest? Any help would be greatly appreciated.