0

How to get all users in SharePoint O365 with Rest API? For example only the username.

1 Answer 1

1

Try below code:

$.ajax({
    url: "https://sitecollectionurl/_api/search/query?querytext='*'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'&selectproperties='AccountName'&rowlimit='500'",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: function (data) {
        console.log(data);
    },
    error: function (data) {
        console.log(data);
    }
}); 

I am using the Search rest api with people source.

Here, i am using the search rest api with people results source to get data from search instead of directly query the user profiles as it give better performance.

If you are using this approach, then Sharepoint search has a default "rowlimit" of 500, so you need to do pagination to get more than 500 profiles as below

SharePoint REST API call with more than 500 rows

2
  • Not sure (because we abstracted all REST calls) does this endpoint work without the RequestDigest? Feb 2, 2017 at 9:26
  • This is a get request , so doesnt require request digest. So yes , it works without request digest. To test i just login to the site, open postman chrome extenstion and paste this request, works without any input required. Feb 2, 2017 at 9:30

Your Answer

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

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