Node.js Box: Get Folder Collaborations

Back to Index

Returns all of the folder's collaborations. This API does not support paging -- it always returns all of the collaborations. Each collaboration object has details on which user or group has access to the file and with what role.

Documentation: https://developer.box.com/reference#view-a-folders-collaborations

CURL Command

curl https://api.box.com/2.0/folders/FOLDER_ID/collaborations \
-H "Authorization: Bearer BOX_ACCESS_TOKEN"

Node.js Example

var os = require('os');
if (os.platform() == 'win32') {  
    var chilkat = require('chilkat_node6_win32'); 
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('chilkat_node6_arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('chilkat_node6_linux32');
    } else {
        var chilkat = require('chilkat_node6_linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('chilkat_node6_macosx');
}

function chilkatExample() {

    var rest = new chilkat.Rest();
    var success;

    //  URL: https://api.box.com/2.0/folders/FOLDER_ID/collaborations
    var bTls = true;
    var port = 443;
    var bAutoReconnect = true;
    success = rest.Connect("api.box.com",port,bTls,bAutoReconnect);
    if (success !== true) {
        console.log("ConnectFailReason: " + rest.ConnectFailReason);
        console.log(rest.LastErrorText);
        return;
    }

    rest.AddHeader("Authorization","Bearer BOX_ACCESS_TOKEN");

    var sbResponseBody = new chilkat.StringBuilder();
    success = rest.FullRequestNoBodySb("GET","/2.0/folders/FOLDER_ID/collaborations",sbResponseBody);
    if (success !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    var jsonResponse = new chilkat.JsonObject();
    jsonResponse.LoadSb(sbResponseBody);

    var total_count;
    var i;
    var count_i;
    var type;
    var id;
    var created_byType;
    var created_byId;
    var created_byName;
    var created_byLogin;
    var created_at;
    var modified_at;
    var expires_at;
    var status;
    var accessible_byType;
    var accessible_byId;
    var accessible_byName;
    var accessible_byLogin;
    var role;
    var acknowledged_at;
    var item;

    total_count = jsonResponse.IntOf("total_count");
    i = 0;
    count_i = jsonResponse.SizeOfArray("entries");
    while (i < count_i) {
        jsonResponse.I = i;
        type = jsonResponse.StringOf("entries[i].type");
        id = jsonResponse.StringOf("entries[i].id");
        created_byType = jsonResponse.StringOf("entries[i].created_by.type");
        created_byId = jsonResponse.StringOf("entries[i].created_by.id");
        created_byName = jsonResponse.StringOf("entries[i].created_by.name");
        created_byLogin = jsonResponse.StringOf("entries[i].created_by.login");
        created_at = jsonResponse.StringOf("entries[i].created_at");
        modified_at = jsonResponse.StringOf("entries[i].modified_at");
        expires_at = jsonResponse.IsNullOf("entries[i].expires_at");
        status = jsonResponse.StringOf("entries[i].status");
        accessible_byType = jsonResponse.StringOf("entries[i].accessible_by.type");
        accessible_byId = jsonResponse.StringOf("entries[i].accessible_by.id");
        accessible_byName = jsonResponse.StringOf("entries[i].accessible_by.name");
        accessible_byLogin = jsonResponse.StringOf("entries[i].accessible_by.login");
        role = jsonResponse.StringOf("entries[i].role");
        acknowledged_at = jsonResponse.StringOf("entries[i].acknowledged_at");
        item = jsonResponse.IsNullOf("entries[i].item");
        i = i+1;
    }


}

chilkatExample();

Sample JSON Response Body

{
  "total_count": 1,
  "entries": [
    {
      "type": "collaboration",
      "id": "14176246",
      "created_by": {
        "type": "user",
        "id": "4276790",
        "name": "David Lee",
        "login": "david@box.com"
      },
      "created_at": "2011-11-29T12:56:35-08:00",
      "modified_at": "2012-09-11T15:12:32-07:00",
      "expires_at": null,
      "status": "accepted",
      "accessible_by": {
        "type": "user",
        "id": "755492",
        "name": "Simon Tan",
        "login": "simon@box.net"
      },
      "role": "editor",
      "acknowledged_at": "2011-11-29T12:59:40-08:00",
      "item": null
    }
  ]
}