Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

How to get All the latest modified files from BOX folder

New post

Comments

8 comments

  • cbetta

    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/

    0
    Comment actions Permalink
  • kanang29

    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'

    0
    Comment actions Permalink
  • cbetta

    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. 

    0
    Comment actions Permalink
  • kanang29

    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.
    }
    }

    =====================================

    0
    Comment actions Permalink
  • cbetta

     hard to tell, it seems right at first glance. What do you get back instead?

    0
    Comment actions Permalink
  • kanang29

    Hi CBetta,
    Thank you for your reply. I do get the response with random dates. I
    need it in descending order (latest modified/created).

    0
    Comment actions Permalink
  • cbetta

    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
    }
    0
    Comment actions Permalink

Please sign in to leave a comment.