To gather the required information for SharePoint Online (SPO), Exchange, and Teams, you can use Microsoft Graph and SharePoint REST APIs. Here are the APIs that will help you get the details :
SharePoint Online (SPO)
Get Site Collection Total Used Storage: Use the SharePoint REST API to get the site collection's storage details.
Example:
httpCopy code
GET https://{tenant}.sharepoint.com/_api/site/usage
Get Total Item/File Count: Use the Microsoft Graph API to get the item count in a document library.
Example:
httpCopy code
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/root/children
Exchange
Get Total Used Storage and Item/Mail Count for a Mail Account: Use the Microsoft Graph API to get the details of a user's mailbox.
Example:
httpCopy code
GET https://graph.microsoft.com/v1.0/users/{user-id}/mailFolders/inbox
To get details for specific folders like primary, group, active, archived, etc., you can iterate through the mail folders:
httpCopy code
GET https://graph.microsoft.com/v1.0/users/{user-id}/mailFolders
Teams
Get Site Collection Total Used Storage and Total Item Count: Since Teams relies on SharePoint for file storage, you can use the same SharePoint REST API and Microsoft Graph API methods as mentioned for SPO to get the storage and item count for Teams files stored in SharePoint.
Example for Teams files in a SharePoint document library:
httpCopy code
GET https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/filesFolder
Permissions
To access these APIs, you will need to register your application in Azure AD and grant the necessary permissions, such as:
- Sites.Read.All (for SharePoint)
- Mail.Read (for Exchange)
- Group.Read.All (for Teams)
Example Code
Here is an example using Microsoft Graph SDK in C# to get mail folder details:
csharpCopy code
GraphServiceClient graphClient =
Replace {tenant}
, {site-id}
, {drive-id}
, {user-id}
, {team-id}
, and {channel-id}
with your actual values.
Make sure to handle authentication and authorization properly to ensure your application can access the required data securely.