I am trying to find the ID of the user using _api/web/siteusers in Office 365
I get User cannot be found.the below error.
User cannot be found
But, when I add user to some people picker field in list item, it starts working
I am using the below code
function GetUserId(userName) {
//userName format = i:0#.f|membership|[email protected]
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
var requesturl = "/_api/web/siteusers(@v)?@v='" + encodeURIComponent(userName) + "'";
if (userName.indexOf("|") < 0) {
requesturl = "/_api/web/sitegroups/getbyname('" + encodeURIComponent(userName) + "')?$select=id";
}
var call = $.ajax({
url: siteUrl + requesturl,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" }
});
return call;
};