Search code examples
graphmicrosoft-graph-api

Graph API Get Full List of Azure AD Groups


I am trying to get a full list of every group in Azure AD. I am currently able to get 999 records with the following uri: https://graph.microsoft.com/v1.0/groups?$top=999

According to the documentation from Microsoft there are only a couple OData query parameters available, none of which appear to be able to navigate to the next page. It also states the maximum page size is 999. I have tried using the $skip parameter to skip a certain number of records, but it is not supported: {"error":{"code":"Request_BadRequest","message":"'$skip' is not supported by the service.",...

Is there any way to get a full list of all AAD groups? We have several thousand that I would need to get.


Solution

  • Some queries against Microsoft Graph return multiple pages of data either due to server-side paging or due to the use of the $top query parameter to specifically limit the page size in a request. When more than one query request is required to retrieve all the results, Microsoft Graph returns an @odata.nextLink property in the response that contains a URL to the next page of results.

    For example, the following URL requests all the users in an organization with a page size of 5, specified with the $top query parameter: https://graph.microsoft.com/v1.0/groups?$top=5

    If the result contains more results, Microsoft Graph will return an @odata.nextLink property similar to the following along with the first page of results:

    You can retrieve the next page of results by sending the URL value of the @odata.nextLink

    ref doc - https://learn.microsoft.com/en-us/graph/paging