How to get the total files size and number for one tenant?

Baojun Guo 1 Reputation point
2024-12-23T04:38:44.6866667+00:00

Hello Team,

How are you? Hope you are all doing well.

I am writing a tool to get the total size and number of all files under Microsoft 365 tenant. I have gone through the Graph API documentation and the Sites and Drive APIs provide document information like file size. We can recursively make API requests to get and calculate the cumulative sum, but this approach is not very efficient. Is there a way can provide the total size and number via a few API requests? Another question is how to make the Drive Delta API return only file info without directory information.

Thanks a lot.

BR,

Baojun

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

1 answer

Sort by: Most helpful
  1. Akhil Nasalwai - MSFT 165 Reputation points Microsoft Vendor
    2025-01-01T16:23:18.9833333+00:00

    Hello Baojun Guo,

    Thank you for contacting Microsoft!

    To get the total size and number of files more efficiently, you can use the Microsoft Graph API with specific queries.

    • Use the siteUsage API: This API provides storage usage details for SharePoint sites. You can call this API for each site collection to get the total storage used and then sum these values across all site collections.
    • Use the driveItem API with $select and $expand parameters. You can use these parameters to filter and expand the properties you need, which can help reduce the amount of data returned and make process more efficient.

    For Drive Delta API to return only file info without directory information, you can use the deltaExcludeParent header. This will ensure that only items that have changed are returned, excluding parent items in the hierarchy.

    After trying the above work arounds, if you still face any issue, I recommend you to raise a support case with Microsoft Graph, a Support Engineer will be able to look into this issue and assist you better. You can raise support ticket from New support request - Microsoft Entra admin center or https://admin.microsoft.com/#/support/requests.

    Hope this helps.

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

    0 comments No comments

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.