How to retrieve all results on API endpoint by looping through using "2op" and "skip"

JamesEdmondsUKPN 5 Reputation points
2023-11-22T12:16:42.68+00:00

Hi,

We are trying to get a device list with install status for a specific app in Intune, and since some recent changes removing a GraphAPI endpoint, we have had to switch to using:

https://graph.microsoft.com/$graphApiVersion/deviceManagement/reports/getDeviceInstallStatusReport

We found this by looking at Edge dev tools while getting this data in the Intune portal.

The issue I am having, is I am having to use "top" and "skip" options in the JSON request body, to retrieve all results. There is no @odata.next option returned for me to use to page through results.

I am therefore using a PowerShell do, while, loop, to increment the "skip" option by 50 results, until the values goes above the total result count.

Sometimes this works perfectly and returns all results, and sometimes it fails and only returns a subset.

Can anyone tell me;

  1. Am I using the right endpoint
  2. Is there a better way to retrieve all results
  3. Is there a request limit on MS GraphAPI
  4. What would cause querying the same URL multiple times in a row to fail sometimes

I can add code if required, but it's more of a general question at the moment.

Thanks

James

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,345 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,703 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Crystal-MSFT 45,911 Reputation points Microsoft Vendor
    2023-11-23T02:07:19.7466667+00:00

    @amesEdmondsUKPN, Thanks for posting in Q&A. For the URL, based on the F12 log on capture, I find it using the same URL you mentioned. But it use Post. and the PayLoad is as below:

    {"select":["DeviceName","UserPrincipalName","Platform","AppVersion","InstallState","InstallStateDetail","AssignmentFilterIdsExist","LastModifiedDateTime","DeviceId","ErrorCode","UserName","UserId","ApplicationId","AssignmentFilterIdsList","AppInstallState","AppInstallStateDetails","HexErrorCode"],"skip":0,"top":50,"filter":"(ApplicationId eq 'xxxxxxxxxx')","orderBy":[]}

    User's image

    Then I am asked to download file to get the report result.

    User's image

    Based on my researching, some GET 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. If you are not receiving an @odata.nextLink property in the response, it is likely that the endpoint does not support server-side paging. In this case, using the $top and $skip query parameters to retrieve all results in a loop is the correct approach. However, there are some limitations to this approach, such as the possibility of hitting request limits on the Microsoft Graph API. It is also possible that querying the same URL multiple times in a row could fail due to various reasons such as network issues or server-side errors.

    https://learn.microsoft.com/en-us/graph/paging?tabs=http

    By default, Microsoft Graph API returns a maximum of 100 items per request. However, you can increase the page size up to a maximum of 999 items per request by using the $top parameter in your API requests.

    https://stackoverflow.com/questions/61628582/how-to-overcome-the-limit-of-records-returned-in-microsoft-graph

    Note: Non-Microsoft link, just for the reference.

    Please change the top value to 999 to see if we can get all the result.


    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.