10

I have the id of the user and I need to get his login name. I use REST API: there is my code :

function ReturnItemBY(fieldName, listname, id, url) {
    //Url should be _spPageContextInfo.webAbsoluteUrl
    // var item = getListItems(url, listName, customquery, '', '');
    //ExecuteOrDelayUntilScriptLoaded(Start, "sp.js");
    var item = null;
    $.ajax({
        url: url + "/_api/web/lists/getbytitle('" + listname + "')/items(" + id + ")",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            // Returning the results
            //alert(data);
            item = data.d;
        },
        async: false
    });
    return item.fieldName;


}

the problem is that he didnt know the name of the list which I put it "Users".

Dose any one know how can get it ,best regards.

2
  • 2
    You ask how to get users, yet your example code is about getting items. I'm not sure if I should show you how to get user in a field (with $expand) or how to get a user by id (from /Users). Sorry, but your question makes no sense to me
    – eirikb
    Commented Nov 22, 2014 at 19:15
  • For me as well.. Commented Nov 22, 2014 at 20:40

2 Answers 2

4

You may want to take a look at this link: Users, groups, and roles REST API reference. As noted by the comments from @eirikb and @Vadim, the url you are using will never give anything close to a list users.

18

I know this question was asked long ago but it might help someone in the future.

If you want to get all the users in your Sharepoint site you can use :

/_api/web/siteusers?

If you want to get the properties of the current user on the site then you can use :

/_api/web/currentUser?

I hope this helps.

2
  • 2
    This is good thanks. I was able to get the Id of someone with this code _api/web/siteUsers?$select=Id,LoginName,Title,Email&$filter=Title eq 'FirstName SecondName'
    – Nathan
    Commented Feb 3, 2021 at 22:11
  • Thanks @Nathan, that really helped. Commented Oct 8, 2021 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.