PowerShell 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}"

PowerShell Example

[Reflection.Assembly]::LoadFile("C:\myAssemblies\ChilkatDotNet47.dll")

$rest = New-Object Chilkat.Rest

#  URL: https://api.dropboxapi.com/2/files/move_v2
$bTls = $true
$port = 443
$bAutoReconnect = $true
$success = $rest.Connect("api.dropboxapi.com",$port,$bTls,$bAutoReconnect)
if ($success -ne $true) {
    $("ConnectFailReason: " + $rest.ConnectFailReason)
    $($rest.LastErrorText)
    exit
}

#  See the Online Tool for Generating JSON Creation Code
$json = New-Object Chilkat.JsonObject
$json.UpdateString("from_path","/Homework/math/ghost_emoji.txt")
$json.UpdateString("to_path","/Halloween/emojis/ghost.txt")
$json.UpdateBool("allow_shared_folder",$false)
$json.UpdateBool("autorename",$false)
$json.UpdateBool("allow_ownership_transfer",$false)

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

$sbRequestBody = New-Object Chilkat.StringBuilder
$json.EmitSb($sbRequestBody)
$sbResponseBody = New-Object Chilkat.StringBuilder
$success = $rest.FullRequestSb("POST","/2/files/move_v2",$sbRequestBody,$sbResponseBody)
if ($success -ne $true) {
    $($rest.LastErrorText)
    exit
}

$respStatusCode = $rest.ResponseStatusCode
if ($respStatusCode -ge 400) {
    $("Response Status Code = " + $respStatusCode)
    $("Response Header:")
    $($rest.ResponseHeader)
    $("Response Body:")
    $($sbResponseBody.GetAsString())
    exit
}

$jsonResponse = New-Object Chilkat.JsonObject
$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
}