I'm using REST API to get user profile properties from SP2013 and it is working for most part of users, but when I try to call for users with apostrophe on the username, I'm getting this error:
"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The expression \\"'domain\\Joe_Doe_O'Brien'\\" is not valid.\"}}}"
On Javascript error object in the return, the status code and status text for this error are:
statusText: Bad Request
statusCode:400
This is a snippet code which I am calling SP2013 rest api:
var accountName = "domain\\Joe_Doe_O'Brien";
var requestHeaders = {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
};
executor = new SP.RequestExecutor(appweburl);
executor.executeAsync(
{
url:
appweburl +
"/_api/SP.UserProfiles.PeopleManager/getpropertiesfor(@v)?@v='" + accountName + "'",
method: "GET",
contentType: "application/json;odata=verbose",
headers: requestHeaders,
success: function (data) {
console.log(data);
},
error: function (jqxr, errorCode, errorThrown) {
console.log(jqxr.responseText);
}
}
);
Also I have tried using encodeURIComponent in accountName variable using account name like this:
var accountName = "domain%5CJoe%5FDoe%5FO%27Brien";
But with no success, the same error still has been thrown.
Has SP2013 REST API limitation using some special char at the username to retrieve user properties?