Welcome to the new Box Support website. Check out all the details here on what’s changed.

Get folder Ids from folder names in API call

New post

Comments

9 comments

  • Bibek

    Hi there,

    First of all 

    l https://api.box.com/2.0/folders/search?query=xxxx&type=folder  this is not even allowed. Not sure how you got the result.

    Only this:  https://api.box.com/2.0/search?query=test&type=folder   is allowed and you can get the folder ID for this. But the problem is it returns multiple results with the same name. So, you can't be sure which folder it is UNLESS you know the "parent" of that folder in which case you can filter it out.

    Lets say you are looking for folder called "Joel and Ellie" and you know it is under folder "Last of Us" then you would see something like:

    {

    "type": "folder",

    "id": 2222,

    "name" : "Joel and Ellie",

    "parent": {
    "type": "folder",
    "id": "removed for privacy1",
    "sequence_id": "2",
    "etag": "2",
    "name": "Last of Us"
    },

    }

    Since you know the parent is "last of us" this must be the folder and has id of 2222. 

     

    Another method is if you know where that folder would be . You can get all items of that specific folder "/folders/FOLDER_ID/items "  and compare the name and get the ID that matches with that name. 

     

    Hope this helps.

    thanks,

    Bibek

     

    0
    Comment actions Permalink
  • Box Product Support

    Thanks Bibek, Actual requirement is to get all the folder items of multiple folders. I tried to use below URL "/folders/FOLDER_ID/items " where i have only list (Multiple) of folder names instead of FOLDER_ID. So iam trying to get the Ids of them. Even I can use the below url if it contains all the folders details of BOX.com. But, its not happening. https://api.box.com/2.0/search?query=test&type=folder It is just returning all folders which contains '%test%'. is there any way to get all the folder detials of box(it should contain Each and every folder). or requested multiple folder details (suppose folder names with xxx, yyy, zzzz) at a sametime. Regards Rajesh

    0
    Comment actions Permalink
  • Bibek

    Hi ,

    It seems like you need to call the /foldres/folder_id/items API but do it recursively. Get all the items and run the folder API again for all items that have type = "folder". Other than that there is no way of getting folders and it's childrens in a single call.

     

     

    thanks,

    Bibek

     

    0
    Comment actions Permalink
  • Box Product Support

    Recursive method will not work out. Already tried..Getting cpu time out. Regards Rajesh

    0
    Comment actions Permalink
  • Bibek

    Well, the recursive method should work but may not be a best approach to do it.

    One alternative that you could try is to generate a report  of all files and folders from the Box admin and work on your requirement. The report should have folder/file IDs and parent ID as well along with all the details.  That report may take a while to pouplate based on how much content you have in Box. (You can always ask Box to provide that info if needed for your company)

     

    thanks,

    Bibek

    0
    Comment actions Permalink
  • Box Product Support

    It is turning out in to a Bottleneck situation. Checking with Admin for the report details and performing other operations is not feasible in dynamic process right? Why cant it happen through API call. Regards, Rajesh

    0
    Comment actions Permalink
  • kattarp

    Hi,

    Look at this, may help you...

    var authenticator = new TokenProvider(clientId, clientSecret);
                    var oAuthToken = authenticator.RefreshAccessToken(refreshToken);
                    accessToken = oAuthToken.AccessToken;
                    BoxTool.Properties.Settings.Default.accessToken = oAuthToken.AccessToken;
                    BoxTool.Properties.Settings.Default.refreshToken = oAuthToken.RefreshToken;
                    var boxManager = new BoxManager(accessToken);

     

    Folder folder = boxManager.GetFolder("FolderId");
    BoxApi.V2.Model.Folder folders = folder.Folder.Single(f => f.Name.Equals("FolderName"));

    0
    Comment actions Permalink
  • Box Product Support

    For this also we need folderid. I have only folder name which is unique. Folder folder = boxManager.GetFolder("FolderId"); BoxApi.V2.Model.Folder folders = folder.Folder.Single(f => f.Name.Equals("FileName"));

    0
    Comment actions Permalink
  • kattarp

    Sorry to say this , here FolderId is the parent Id of the folder which you are trying to retrieve.

     

    Ok, if you are having not at all an Id, then you can try one thing "Folder.Root" i.e "0" (Zero) is the Parent for all. Hence

    Folder folder = boxManager.GetFolder("0");
    IEnumerable folders = folder.Folders;

     

    Then Recursive Loop from here

     

    (OR) please look at this

    https://docs.box.com/reference#get-collections and https://docs.box.com/reference#collections-beta

    0
    Comment actions Permalink

Please sign in to leave a comment.