Skip to main content
Question

How to get the Version Number of the Previous File Versions?

  • May 21, 2025
  • 4 replies
  • 41 views

Forum|alt.badge.img

I am able to get the current version Number of a file, but the previous version number i am unable to find a way to get that. Please help me on this

4 replies

Forum|alt.badge.img

 You can use the Get Versions endpoint to get information about previous versions of a file. 


Forum|alt.badge.img

Actually using the BOX-SDK, I wanted to fetch the previous version number of the versions,

like info.getVersionNumber() method, i want to get the previous versions version number.


Forum|alt.badge.img
        BoxFile file = new BoxFile(userApi, "xxxxxx");
        System.out.println("file current version: " + file.getInfo().getVersion().getVersionID());

        Collection versions = file.getVersions();   // Fetching the Previous Version of the Files
        int versionIndex = versions.size();
        if (versions.size() != 0) {     // If there is no Previous Versions
            for (BoxFileVersion bfv : versions) {
                if (versionIndex == versions.size())  // the first one is the previous version
                {
                    bfv.promote();
                    bfv.delete();
                    System.out.println("Deleted Version ID : "+ bfv.getVersionID());
                }
                System.out.println("bfv: [" + versionIndex-- + "] " + bfv.getVersionID() + " " + bfv.getCreatedAt());
            }
        }

Forum|alt.badge.img

I think one more condition to be added to the code given by , for checking the Trashed previous versions. Correct me if i am wrong.      

         

 if(bfv.getTrashedAt() == null){
                bfv.promote();
                bfv.delete();
                System.out.println("Deleted Version ID : "+ bfv.getVersionID());
 }