Microsoft Graph API | GET users doesn't pull all entries

Rory Van Vuuren 21 Reputation points
2022-12-14T17:23:17.327+00:00

I am a Global Admin of our tenant, however, whenever I do an API GET request (ie https://graph.microsoft.com/v1.0/users/), I am only getting the first 78 users of well over 900.

I am getting the same results directly from the Microsoft Graph tool as what I am seeing in my python script.

I have created an app registration in our tenant that has the necessary permissions per this document (https://learn.microsoft.com/en-gb/graph/api/user-list?view=graph-rest-1.0&tabs=http)

Does anyone have an idea of what could be limiting my results like that?

Microsoft Security Microsoft Entra Microsoft Entra ID
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Zehui Yao_MSFT 5,876 Reputation points
    2022-12-15T03:14:00.36+00:00

    Hi @Rory Van Vuuren , I test locally and found that there is limitation of the $top parameter. Invalid page size specified: '1000'. Must be between 1 and 999 inclusive.

    And I suggest using the $count=true parameter to retrieve the count of the total number of items in a collection, this way you can confirm the quantity (please note the ConsistencyLevel header is required here). Hope this helps you. Best Wishes.

    270737-image.png

    270781-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Vicky Kumar (Mindtree Consulting PVT LTD) 1,161 Reputation points Microsoft Employee
    2022-12-14T18:47:31.957+00:00

    You will not get all the data once, could you please try using $top (900) in your query , See the doc to know more about paging - https://learn.microsoft.com/en-us/graph/paging

    Try below API

    API - https://graph.microsoft.com/v1.0/users?$top=900

    Hope this helps

    Thanks

    1 person found this answer helpful.

  2. Gopinath Chennamadhavuni 2,446 Reputation points
    2022-12-15T01:43:39.27+00:00

    Hi @Rory Van Vuuren ,

    Thanks for reaching out.

    Most of the endpoints in Microsoft Graph return data in pages, this includes /users.
    In order to retrieve the rest of the results you need to look through the pages.

    Microsoft Graph API returns the user in a pagination format so to get the next list of users you will have to query the url which is mentioned in @odata.nextLink of your current response and that will give you next set of users.

    To achieve this, you can run a for loop till the time @odata.nextLink returns NULL value.

    Reference link: https://learn.microsoft.com/en-us/graph/paging

    a. Queried graph api to fetch users

    270725-inkeduser1-li.jpg

    b. Queried graph api with "@odata.nextLink" to get next set of users

    270733-inkeduser2-li.jpg
    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.