How to get All the latest modified files from BOX folder
I am looking for an API to get all the latest created/modified files under one folder. How do i do it? I am trying this curl -X GET https://api.box.com/2.0/search?query=9***phone number removed for privacy***,2020-04-20,2020-04-22 -H 'Authorization: Bearer L5n8P6F4VNSFTCVDHPYs16kxtvJAZ1Ht' 9***phone number removed for privacy*** - ancestor folder id 20,2020-04-20,2020-04-22 created_at_range It does not work for me.
-
Hi
Search is meat to search for content in files in a folder. As you don't really have a query string to search for I doubt this is what you want.
You have two options: 1, you can list the items in a folder by date. https://developer.box.com/reference/get-folders-id-items/#param-sort. This would allow you to inspect all items in a folder and compare it to the latest date. This is perfect for small folders but gets unwieldy for larger ones.
For larger ones, you can listen to the event feed for a user and watch for any events for that user that change a file in that folder. https://developer.box.com/reference/get-events/
-
Hi Box Customer Service,
Thank you for your reply.
When I execute a curl
curl -X GET
https://api.box.com/2.0/folders/9***phone number removed for privacy***/items?direction=DESC&sort=date&limit=20
-H 'Authorization: Bearer p1YyiXGc8UifVasqjm1bwkdm3PwaGU7Z'
I want to get 20 latest created/modified files and this should solve my
problem.
Below mentioned command works but displays the oldest file on the top.
Sorts ASC by default.
curl -X GET https://api.box.com/2.0/folders/9***phone number removed for privacy***/items?sort=date -H
'Authorization: Bearer p1YyiXGc8UifVasqjm1bwkdm3PwaGU7Z' -
I'd take a deeper look at the API reference for this call. We have all parameters listed here:
https://developer.box.com/reference/get-folders-id-items/
As you can see, there is a "direction" parameter.
-
Hi Box Support Team,
Thank you for your quick response. I could make the curl command work. I would like to implement it using Java SDK
This command gives me 20 latest created/modified files. Now
curl -X GET "https://api.box.com/2.0/folders/9***phone number removed for privacy***/items?sort=date&limit=20&direction=DESC" -H 'Authorization: Bearer TvYjmFlwydJfSKnG2GCYcbWWJY4IZwRg'
======================================================Below mentioned code does not give me the exact results like the curl command above. What is it that I am missing here?
BoxAPIConnection boxAdminAppUserApiConnection = this.getAppUserConnection(this.boxAdminAppUser);
BoxFolder folderSearched = new BoxFolder(boxAdminAppUserApiConnection, folderId);
Iterable searchResults = folderSearched.getChildren(sort, limit,"DESC");
try {
for (BoxItem.Info itemInfo : searchResults) {
if (itemInfo instanceof BoxFile.Info) {
BoxFile.Info fileInfo = (BoxFile.Info) itemInfo;
fileList.add(generateDriveFileVO(fileInfo, Boolean.FALSE)); //no shallow fetch
// Do something with the file.
} else if (itemInfo instanceof BoxFolder.Info) {
BoxFolder.Info folderInfo = (BoxFolder.Info) itemInfo;
// Do something with the folder.
}
}
===================================== -
Going off the Java SDK docs, the API should work as follows.
BoxFolder folder = new BoxFolder(this.api, "12345"); Iterator<BoxItem.Info> itemIterator = folder.getChildren("name", BoxFolder.SortDirection.ASC).iterator(); while (itemIterator.hasNext()) { BoxItem.Info itemInfo = itemIterator.next(); // Do something }
-
Please sign in to leave a comment.
Comments
8 comments