PHP Extension 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

PHP Extension Example

<?php

// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");

$rest = new CkRest();

//  URL: https://api.box.com/2.0/folders/47885473705?recursive=true
$bTls = true;
$port = 443;
$bAutoReconnect = true;
$success = $rest->Connect('api.box.com',$port,$bTls,$bAutoReconnect);
if ($success != true) {
    print 'ConnectFailReason: ' . $rest->get_ConnectFailReason() . "\n";
    print $rest->lastErrorText() . "\n";
    exit;
}

$rest->AddHeader('Authorization','Bearer BOX_ACCESS_TOKEN');

$sbResponseBody = new CkStringBuilder();
$success = $rest->FullRequestNoBodySb('DELETE','/2.0/folders/47885473705?recursive=true',$sbResponseBody);
if ($success != true) {
    print $rest->lastErrorText() . "\n";
    exit;
}


?>