Java Box: Delete Folder

Back to Index

Move a folder to the trash. The recursive parameter must be included in order to delete folders that aren't empty. This example deletes the folder w/ id = 47885473705. An empty 204 response will be returned upon successful deletion. An error is thrown if the folder is not empty and the ‘recursive’ parameter is not included.

Documentation: https://developer.box.com/reference#delete-a-folder

CURL Command

curl https://api.box.com/2.0/folders/47885473705?recursive=true \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" \
-X DELETE

Java Example

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://api.box.com/2.0/folders/47885473705?recursive=true
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("api.box.com",port,bTls,bAutoReconnect);
    if (success != true) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(rest.lastErrorText());
        return;
        }

    rest.AddHeader("Authorization","Bearer BOX_ACCESS_TOKEN");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestNoBodySb("DELETE","/2.0/folders/47885473705?recursive=true",sbResponseBody);
    if (success != true) {
        System.out.println(rest.lastErrorText());
        return;
        }
  }
}