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

PowerBuilder Example

integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JsonResponse
string ls_From_path
string ls_To_path
integer li_Allow_shared_folder
integer li_Autorename
integer li_Allow_ownership_transfer

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  URL: https://api.dropboxapi.com/2/files/move_v2
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("api.dropboxapi.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

//  See the Online Tool for Generating JSON Creation Code
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("from_path","/Homework/math/ghost_emoji.txt")
loo_Json.UpdateString("to_path","/Halloween/emojis/ghost.txt")
loo_Json.UpdateBool("allow_shared_folder",0)
loo_Json.UpdateBool("autorename",0)
loo_Json.UpdateBool("allow_ownership_transfer",0)

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

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Json.EmitSb(loo_SbRequestBody)
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestSb("POST","/2/files/move_v2",loo_SbRequestBody,loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Json
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    return
end if

li_RespStatusCode = loo_Rest.ResponseStatusCode
if li_RespStatusCode >= 400 then
    Write-Debug "Response Status Code = " + string(li_RespStatusCode)
    Write-Debug "Response Header:"
    Write-Debug loo_Rest.ResponseHeader
    Write-Debug "Response Body:"
    Write-Debug loo_SbResponseBody.GetAsString()
    destroy loo_Rest
    destroy loo_Json
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    return
end if

loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonResponse.LoadSb(loo_SbResponseBody)

//  See the Online Tool for Generating JSON Parse Code

ls_From_path = loo_JsonResponse.StringOf("from_path")
ls_To_path = loo_JsonResponse.StringOf("to_path")
li_Allow_shared_folder = loo_JsonResponse.BoolOf("allow_shared_folder")
li_Autorename = loo_JsonResponse.BoolOf("autorename")
li_Allow_ownership_transfer = loo_JsonResponse.BoolOf("allow_ownership_transfer")


destroy loo_Rest
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JsonResponse

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
}