Graph api not returning all subfolders from sharepoint folder

Kaustubh Nangare 0 Reputation points
2023-05-18T05:39:21.0633333+00:00

Hi,

I am using graph api to fetch folder's subfolder from SharePoint, using this endpoint
https://graph.microsoft.com/v1.0/sites/<site-id>/drives/<drive-id>/items/<item-id>/children?select=id%2Cname%2CdisplayName%2Cdescription%2CcreatedBy%2ClastModifiedBy%2CcreatedDateTime%2ClastModifiedDateTime%2CwebUrl%2C%40microsoft.graph.downloadUrl%2CdriveId%2CdriveType%2Cpath%2CparentReference%2Clist%2CcontentType%2Croot%2CsiteCollection%2C%40odata.type%2C%40odata.etag%2CeTag%2C%40odata.context%2Cfields%40odata.context%2Cuser%2Cemail%2Cvalue%2CcontentTypesEnabled%2Chidden%2Ctemplate%2Chostname%2Cfields%40odata.context%2Cpackage%2Ctype%2Cfolder
In the response I see that not all folders which are visible to user from SharePoint UI are returned, some of them are missing in API response. There is no @odata.nextLink returned in response as well.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,316 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,211 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 33,481 Reputation points Microsoft Vendor
    2023-05-18T07:11:21.3133333+00:00

    Hi @Kaustubh Nangare,

    Per your description, I will recommend you to try following solutions

    1. Pagination: The Graph API paginates results to improve performance. By default, the API returns a limited number of results per page. You can use the $top and $skip query parameters to control pagination and retrieve more results. For example, you can increase the $top value to fetch more items in a single request.
    2. Permissions: Ensure that the authenticated user or the application accessing the Graph API has the necessary permissions to access the SharePoint site, folders, and files. Check the user's permissions in SharePoint and verify that the app registration or authentication token includes the appropriate scopes and permissions for accessing the required SharePoint resources.
      1. Filtering and Expansion: When querying the Graph API, you may need to include additional query parameters to retrieve subfolders. For example, you can use the $expand parameter to expand the children property and fetch all child items, including subfolders. The expanded response will provide information about subfolders and files within the parent folder.

    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.