I need to list all AAD users using Graph

Filip Gajdosik 20 Reputation points
2023-04-18T15:17:58.66+00:00

Our organization has over 1000 users, and I am currently working on a project where I need to programmatically interact with the entire list of users using a Logic App. While utilizing the Microsoft Graph API, I've come across the @odata.nextLink pagination feature, which is proving to be cumbersome when working with such a large user base. I tried to increase the result limit by setting $top=2000 like so: https://graph.microsoft.com/v1.0/users?$top=2000, but it appears that the maximum limit for the $top parameter is capped at 999. Given the constraints of the API and the size of our user base, I am seeking an alternative or more efficient approach to retrieve the complete list of users without having to iterate through multiple pages using @odata.nextLink. Ideally, I would like to minimize the number of API calls and simplify the process in my Logic App (which currently doesn't work because I wasn't able to figure out the foreach and/or until cycle). Is there a recommended method or best practice for obtaining a full list of users in cases like ours, where the number of users exceeds the maximum limit for the $top parameter? Any guidance, suggestions, or workarounds would be greatly appreciated.

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,284 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,241 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,054 questions
0 comments No comments
{count} votes

Accepted answer
  1. Gopinath Chennamadhavuni 2,436 Reputation points
    2023-04-19T03:49:37.3666667+00:00

    Hi @Filip Gajdosik,

    Thanks for reaching out.

    Paging is designed to return a limited set of data. This is by design for APIs that can return large sets of data, so the client and server do not get overwhelmed. Most APIs that support paging have an upper limit on how much you can request at once irrelevant of how much you ask for.

    You have to keep calling the API with the next link until you get all the data. This is how paging works and there is no workaround. You can read all about paging in the Graph API here. Note that the specifics of paging various by the resource the API is wrapping but in general if you ask for $top=X then the API will return at most X records. If X is greater than what the underlying API allows it may either error or return the server-specified max results. This is by design and not something you can change.

    Hope this helps.

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

    0 comments No comments

0 additional answers

Sort by: Most helpful

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.