Sharepoint - Retrieve site collection quota and used storage from REST or JSOM

The REST query

https://<siteUrl>/_api/site/usage

will return the following:

{
    "d": {
        "Usage": {
            "__metadata": {
                "type": "SP.UsageInfo"
            },
            "Bandwidth": "0",
            "DiscussionStorage": "0",
            "Hits": "0",
            "Storage": "354721461",
            "StoragePercentageUsed": 0.0330360104329884,
            "Visits": "0"
        }
    }
}

Storage will give us "Storage Used"(in Bytes) not the "Total Storage" you can calculate the amount of storage used based on Storage and StoragePercentageUsed


How to access information about site collection usage via CSOM

SP.UsageInfo object provides fields that are used to access information about site collection usage.

var context = new SP.ClientContext.get_current();
var site = context.get_site();
context.load(site,'Usage');  
context.executeQueryAsync(
    function() {

        var siteUsageInfo = site.get_usage();                   
        console.log(siteUsageInfo.get_storage());          
        console.log(siteUsageInfo.get_storagePercentageUsed());             
    },
    function(sender,args){
       console.log(args.get_message());
    }
);

Tags:

Rest

Quota