Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Box.com Search API to retrieve all files in a determined folder

Tags:

search

box-api

I'm searching a way to obtain all files of a specific folder.

But I can't find sufficient informations in the official documentation

I think about something like this: (I assume also to set a custom header with the access_token)

https://api.box.com/2.0/search?query=*

This way doesn't work, and I think that the query doen't accept a regex...

Any idea?


PS: A real usecase will help to understand this question:

my folder:

folderOne:
 |
 |_file1.jpg
 |
 |_file2.doc
 |
 |_folder1
 | |_file3.jpg
 | |_folder2
 |
 |_file4.pdf

with the search request I expect to get only file1.jpg, file2.doc and file4.pdf.

like image 375
RikyTres Avatar asked Jun 09 '14 14:06

RikyTres


People also ask

How can I search data in a folder?

To search for files in File Explorer, open File Explorer and use the search box to the right of the address bar. Tap or click to open File Explorer. Search looks in all folders and subfolders within the library or folder you're viewing. When you tap or click inside the search box, the Search Tools tab appears.

Which option is used to search files and folders?

This is Expert Verified AnswerFile Explorer allows you to use Windows Search Explorer (by default) to help you find and view all of your files or folders in one place.

What is the easiest way to search a folder?

Search File Explorer: Open File Explorer from the taskbar or right-click on the Start menu, choose File Explorer and then select a location from the left pane to search or browse. For example, select This PC to look in all devices and drives on your computer, or select Documents to look only for files stored there.


1 Answers

You can most easily accomplish this by querying for a folder's contents and then filtering client-side for the file items.

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

This will return a collection of items, from which you can select those whose type is file.

{
  "total_count": 4,
  "entries": [
     {
        "type": "folder",
        "id": "192429928",
        "name": "folder1"
     },
     {
        "type": "file",
        "id": "818853862",
        "name": "file1.jpg"
     },
     {
        "type": "file",
        "id": "818853843",
        "name": "file2.doc"
     },
     {
        "type": "file",
        "id": "818853832",
        "name": "file4.pdf"
     }
  ]
}

Pagination

Box will return all folder metadata before any file metadata. You can count these folders to determine the appropriate offset for file-only paging. For example, if your Box folder has 13 subfolders, and you want to page 25 files at a time:

/folders/FOLDER_ID/items?limit=25&offset=13
/folders/FOLDER_ID/items?limit=25&offset=38
/folders/FOLDER_ID/items?limit=25&offset=63
/folders/FOLDER_ID/items?limit=25&offset=...
like image 108
John Hoerr Avatar answered Sep 30 '22 00:09

John Hoerr