msgraph folders endpoint is raising threshold exception

Marco Dissel 26 Reputation points
2023-09-11T08:00:31.58+00:00

I'm using the folders endpoint to load all the folders. The folder contains > 5000 files and folders and the API is returning a threshold exception. How can I tweak the folders() request to bypass the threashold problem?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,881 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 41,291 Reputation points
    2023-09-12T09:16:58.9366667+00:00

    Hi @Marco Dissel

    This looks like a threshold exception caused by the amount of data returned being too large.

    One possible way to tweak the API request to bypass the threshold problem is to use the $top query parameter to specify the maximum number of items to return per page. For example, you can use something like this:

    https://graph.microsoft.com/v1.0/me/drive/root/children?$top=100
    

    This will return only the first 100 items in the root folder, along with a nextLink property that contains the URL to get the next page of items. You can then use the nextLink URL to get the next 100 items, and so on, until you get all the items in the folder. This way, you can avoid getting a large number of items in one request, which can trigger the threshold exception.

    Hope this helps.

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


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.