9

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.

Imen Turki
  • 2,183
  • 9
  • 35
  • 59
  • 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 Nov 22 '14 at 19:15
  • For me as well.. – Vadim Gremyachev Nov 22 '14 at 20:40

2 Answers2

17

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.

Memphis335
  • 333
  • 4
  • 15
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.

cubanGuy
  • 518
  • 3
  • 11
  • 24