Reputation: 11
I'm trying to programatically get OneDrive for Business Storage/Quota for all users within our tenant.
Have tried using the https://mytenant-my.sharepoint.com/_api/site/usage
API call, but this doesn't accurately represent the size of our OneDrive usage.
Has anyone had any experience of getting this information and how best to get it?
Upvotes: 1
Views: 481
Reputation: 130
There is no such endpoint like /sites/usage according to the documentation.
Instead call for GET --> https://{tenant}-my.sharepoint.com/_api/v2.0/drive and get drive information. In the drive response you will be having QUOTA facet.
Sample response response has been truncated for readability.
{
"id": "string",
"driveType": "personal | business",
"owner": { "@odata.type": "oneDrive.identitySet" },
"quota": { "@odata.type": "oneDrive.quota" },
"items": [ { "@odata.type": "oneDrive.item" } ],
"root": { "@odata.type": "oneDrive.item" },
"special": [ { "@odata.type": "oneDrive.item" }]
}
Here you can get the storage/quota information.
Upvotes: 1
Reputation: 241
You have the right _api format to get the usage statistics but you need to specify the full path to each users' OneDrive for Business site in the URL.
For example:
https://mytenant-my.sharepoint.com/personal/user_mytenant_com/_api/site/usage
For each user in your organisation, call that REST Api URL but replace the user_mytenant_com part with the username of the current user.
By default an Office 365 tenant administrator does not have access to a user's OneDrive for Business site so I don't think you will be able to call the REST Api method without first adding your user as an administrator of their OneDrive for Business site.
Upvotes: 0