Sample code for 30+ languages & platforms
Node.js

Dropbox: Get Space Usage

See more Dropbox Examples

Demonstrates how to get the Dropbox space usage information for the current user's account.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    var rest = new chilkat.Rest();

    //  Connect to the www.dropbox.com endpoint.
    var bTls = true;
    var port = 443;
    var bAutoReconnect = true;
    success = rest.Connect("api.dropboxapi.com",port,bTls,bAutoReconnect);
    if (success !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    rest.AddHeader("Authorization","Bearer DROPBOX-ACCESS-TOKEN");

    var responseStr = rest.FullRequestNoBody("POST","/2/users/get_space_usage");
    if (rest.LastMethodSuccess !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    //  Success is indicated by a 200 response status code.
    if (rest.ResponseStatusCode !== 200) {
        //  Examine the request/response to see what happened.
        console.log("response status code = " + rest.ResponseStatusCode);
        console.log("response status text = " + rest.ResponseStatusText);
        console.log("response header: " + rest.ResponseHeader);
        console.log("response body (if any): " + responseStr);
        console.log("---");
        console.log("LastRequestStartLine: " + rest.LastRequestStartLine);
        console.log("LastRequestHeader: " + rest.LastRequestHeader);
        return;
    }

    var jsonResponse = new chilkat.JsonObject();
    jsonResponse.Load(responseStr);

    jsonResponse.EmitCompact = false;
    console.log(jsonResponse.Emit());

    //  {
    //    "used": 3032115,
    //    "allocation": {
    //      ".tag": "individual",
    //      "allocated": 2147483648
    //    }
    //  }
    //  

}

chilkatExample();