Perl Dropbox: Dropbox Move a File to another Folder

Back to Index

Move a file or folder to a different location in the user's Dropbox. If the source path is a folder all its contents will be moved.

Documentation: https://www.dropbox.com/developers/documentation/http/documentation#files-move

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/move_v2 \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"from_path\": \"/Homework/math/ghost_emoji.txt\",\"to_path\": \"/Halloween/emojis/ghost.txt\",\"allow_shared_folder\": false,\"autorename\": false,\"allow_ownership_transfer\": false}"

Perl Example

use chilkat();

$rest = chilkat::CkRest->new();

#  URL: https://api.dropboxapi.com/2/files/move_v2
$bTls = 1;
$port = 443;
$bAutoReconnect = 1;
$success = $rest->Connect("api.dropboxapi.com",$port,$bTls,$bAutoReconnect);
if ($success != 1) {
    print "ConnectFailReason: " . $rest->get_ConnectFailReason() . "\r\n";
    print $rest->lastErrorText() . "\r\n";
    exit;
}

#  See the Online Tool for Generating JSON Creation Code
$json = chilkat::CkJsonObject->new();
$json->UpdateString("from_path","/Homework/math/ghost_emoji.txt");
$json->UpdateString("to_path","/Halloween/emojis/ghost.txt");
$json->UpdateBool("allow_shared_folder",0);
$json->UpdateBool("autorename",0);
$json->UpdateBool("allow_ownership_transfer",0);

$rest->AddHeader("Authorization","Bearer DROPBOX-ACCESS-TOKEN");
$rest->AddHeader("Content-Type","application/json");

$sbRequestBody = chilkat::CkStringBuilder->new();
$json->EmitSb($sbRequestBody);
$sbResponseBody = chilkat::CkStringBuilder->new();
$success = $rest->FullRequestSb("POST","/2/files/move_v2",$sbRequestBody,$sbResponseBody);
if ($success != 1) {
    print $rest->lastErrorText() . "\r\n";
    exit;
}

$respStatusCode = $rest->get_ResponseStatusCode();
if ($respStatusCode >= 400) {
    print "Response Status Code = " . $respStatusCode . "\r\n";
    print "Response Header:" . "\r\n";
    print $rest->responseHeader() . "\r\n";
    print "Response Body:" . "\r\n";
    print $sbResponseBody->getAsString() . "\r\n";
    exit;
}

$jsonResponse = chilkat::CkJsonObject->new();
$jsonResponse->LoadSb($sbResponseBody);

#  See the Online Tool for Generating JSON Parse Code

$from_path = $jsonResponse->stringOf("from_path");
$to_path = $jsonResponse->stringOf("to_path");
$allow_shared_folder = $jsonResponse->BoolOf("allow_shared_folder");
$autorename = $jsonResponse->BoolOf("autorename");
$allow_ownership_transfer = $jsonResponse->BoolOf("allow_ownership_transfer");

Sample JSON Response Body

{
  "from_path": "/Homework/math/ghost_emoji.txt",
  "to_path": "/Halloween/emojis/ghost.txt",
  "allow_shared_folder": false,
  "autorename": false,
  "allow_ownership_transfer": false
}