msgraph folders endpoint is raising threshold exception

Marco Dissel 26 Reputation points

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 Files API
Microsoft Graph Files API
A Microsoft API to create an app that connects with files across OneDrive, OneDrive for Business, and SharePoint document libraries.
392 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 28,366 Reputation points

    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:$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.