Skip to main content
added 14 characters in body
Source Link

User cannot be found. Not able to get ID of user using their user name - error in _api/web/siteusers

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;
};

User cannot be found. error in _api/web/siteusers

I am trying to find the ID of the user using _api/web/siteusers in Office 365

I get User cannot be found. error.

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;
};

Not able to get ID of user using their user name - error in _api/web/siteusers

I am trying to find the ID of the user using _api/web/siteusers in Office 365

I get 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;
};
added 14 characters in body
Source Link

I am trying to find the ID of the user using _api/web/siteusers in Office 365

I get User cannot be found. error.

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;
};

I am trying to find the ID of the user using _api/web/siteusers

I get User cannot be found. error.

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;
};

I am trying to find the ID of the user using _api/web/siteusers in Office 365

I get User cannot be found. error.

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;
};
Source Link

User cannot be found. error in _api/web/siteusers

I am trying to find the ID of the user using _api/web/siteusers

I get User cannot be found. error.

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;
};