4

Is there any way to get all files and folder in box without knowing their id? Also, how to get all collaboration objects if I don't know collaboration id?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
user2384432
  • 51
  • 1
  • 1
  • 2

4 Answers4

11

You can get root folders and files by specifying folder id = 0. And with this result further folders or files can also be fetched.

Shanky Munjal
  • 671
  • 5
  • 18
2

You can use Get Folder Items on a folder id you do know to retrieve the IDs of the folders and files that it contains. As Shanky says, use 0 to start at the root folder.

Get Collaborations will show the collaborations on a folder. You don't need any information about the collaboration, just the folder id.

tufelkinder
  • 1,176
  • 1
  • 15
  • 37
0

Unlike systems that are built exclusively on path-access, Box gives you a durable ID for each folder and file. This has a bunch of advantages. One of the big ones is that you can rename, or move a file around, and getting to it never needs to change. It also means that you can persist the IDs, associate them with some other entity in your own system, and still be able to get back to the same file or folder. Assuming of course that you are still allowed access to it. Permissions can change too of course.

You can get all the collaborations for a user by calling GET /collaborations or all the collaborations on a folder by calling GET /folder/ID/collaborations

Peter
  • 2,551
  • 1
  • 14
  • 20
  • I am trying to get the collaboration for a given folder. In the Box sdk function given on github the function is public Collaboration GetCollaboration(string collaborationId, IEnumerable fields = null). My question is how do i get the collaboration ID??? After reading the above comments I thought the ID of a given folder is to be given but when i provide that I get an exception "404 not found". Although my folder id "xxxxxx" does have a collaboration enabled. – Alok Ranjan Jun 06 '13 at 10:41
0

Call listFilesInBoxFolders("0") ---> This will parse all files and folders starting from root

public void listFilesInBoxFolders(String folderId) {

    try {
        // get a list of songs
        BoxApiFolder folderApi = new BoxApiFolder(mSession);
        BoxListItems items = folderApi.getItemsRequest(folderId).send();

        JSONObject object = new JSONObject(items.toJson());

        LogUtils.log(TAG, "Object " + object.toString());

        JSONArray array = object.getJSONArray("entries");

        for (int i = 0; i < array.length(); i++) {
            JSONObject object1 = array.getJSONObject(i);
            String type = object1.getString("type");
            String id = object1.getString("id");
            String name = object1.getString("name");
            if (type.equals("folder")) {
                listFilesInBoxFolders(id);
            } else if (type.equals("file")) {
                // Supported Media file types
                if (name.contains("mp3") || name.contains("m4a") || name.contains("flac")) {
                    musicItems.add(new BoxMusicItem(id, name));
                }
            }
        }

        LogUtils.log(TAG, "array " + array.toString());

    } catch (BoxException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
        LogUtils.log(TAG, "Json Error");
    }
    // For testing to make sure i have all files in box
    printFilesInBox();
 }
user3335966
  • 2,673
  • 4
  • 30
  • 33
Andy Cass
  • 398
  • 6
  • 16