This question is an extension of this one I found as a starting point (which works without special characters): SharePoint REST query SP.UserProfiles.PeopleManager
Basically the problem I am having is the query does not accurately respond to accountName
with special characters. Specifically, a '
in the last name for this example. The query either returns no results or is a 400 Bad Request.
In the code example I have used encodeURIComponent()
, but I have also tried escape()
and string escapes "\"
.
At this point I am assuming its a bug on the MS side, but I cannot find any support documentation, nor any examples of code that have done this successfully.
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
var accountName = "Domain\\LoginFirstName_O'AccountLastName";
$.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);
},
error: function (data) {
console.log(JSON.stringify(data));
}
});