Get folder Ids from folder names in API call
Hi Team, Trying to get Folder ids from Folder names using the below url https://api.box.com/2.0/folders/search?query=xxxx&type=folder Cannot able to get the folder ids. Where as i can able to get file ids when i use same with file names with below URL. https://api.box.com/2.0/search?query=Riskextract.csv Is there any other way to get folderid if i have folder names? Regards Rajesh Nagandla ***@example.com
-
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
-
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
-
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
-
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")); -
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
Please sign in to leave a comment.
Comments
9 comments