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

DataFlex Example

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Integer iRespStatusCode
Response    Handle hoJsonResponse
    String sFrom_path
    String sTo_path
    Boolean iAllow_shared_folder
    Boolean iAutorename
    Boolean iAllow_ownership_transfer
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    //  URL: https://api.dropboxapi.com/2/files/move_v2
    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "api.dropboxapi.com" iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  See the Online Tool for Generating JSON Creation Code
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "from_path" "/Homework/math/ghost_emoji.txt" To iSuccess
    Get ComUpdateString Of hoJson "to_path" "/Halloween/emojis/ghost.txt" To iSuccess
    Get ComUpdateBool Of hoJson "allow_shared_folder" False To iSuccess
    Get ComUpdateBool Of hoJson "autorename" False To iSuccess
    Get ComUpdateBool Of hoJson "allow_ownership_transfer" False To iSuccess

    Get ComAddHeader Of hoRest "Authorization" "Bearer DROPBOX-ACCESS-TOKEN" To iSuccess
    Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestSb Of hoRest "POST" "/2/files/move_v2" vSbRequestBody vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Status Code = " iRespStatusCode
        Showln "Response Header:"
        Get ComResponseHeader Of hoRest To sTemp1
        Showln sTemp1
        Showln "Response Body:"
        Get ComGetAsString Of hoSbResponseBody To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
    If (Not(IsComObjectCreated(hoJsonResponse))) Begin
        Send CreateComObject of hoJsonResponse
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess

    //  See the Online Tool for Generating JSON Parse Code

    Get ComStringOf Of hoJsonResponse "from_path" To sFrom_path
    Get ComStringOf Of hoJsonResponse "to_path" To sTo_path
    Get ComBoolOf Of hoJsonResponse "allow_shared_folder" To iAllow_shared_folder
    Get ComBoolOf Of hoJsonResponse "autorename" To iAutorename
    Get ComBoolOf Of hoJsonResponse "allow_ownership_transfer" To iAllow_ownership_transfer


End_Procedure

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
}