cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't delete files with powershell

Can't delete files with powershell

lucaortis
Explorer | Level 4

 

 

 

function DropBox-FileDelete {

    Param (
        [Parameter(Mandatory=$true)]
        [string]$SourceFilePath
    )

    $DropBoxAccessToken = TOKEN HERE 
    $testFile = $SourceFilePath
    $TargetFilePath="/$testFile"
    $arg = '{"path": "' + $TargetFilePath + '"}'
    
    $authorization = "Bearer " + $DropBoxAccessToken

    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Authorization", $authorization)
    $headers.Add("Content-Type", 'application/json')
    
    try {
        $result = Invoke-RestMethod -Uri https://api.dropboxapi.com/2/files/delete_v2 -Method Post -Headers $headers -Body $arg
    }
    catch {
        $result = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($result)
        $reader.BaseStream.Position = 0
        $reader.DiscardBufferedData()
        $responseBody = $reader.ReadToEnd();
    }
    Write-Output $responseBody
}

DropBox-FileDelete "/Applicazioni/Costumer Manager Files/Ore.txt"

 

 

Hello. I just started using the API and I ran into this issue: 
I can upload files, I can download files but I cannot delete them.  

What am I missing here? 
It seems a path problem, but to me the path is fine. 
If the path was wrong, then I would not be able to upload or download, instead, I can download and upload just fine. 

Response body: 

 

 

{"error_summary": "path_lookup/malformed_path/", "error": {".tag": "path_lookup", "path_lookup": {".tag": "malformed_path"}}}

 

 

 

3 Replies 3

Здравко
Legendary | Level 20

@lucaortis wrote:

...
It seems a path problem, but to me the path is fine. 
If the path was wrong, then I would not be able to upload or download, instead, I can download and upload just fine. 

...


Hi @lucaortis,

You haven't posted the code responsible for upload and download. Are you using in the path there double leading slashes too? 🤔😁😉

Hope this gives direction.

Greg-DB
Dropbox Staff

@lucaortis As Здравко pointed out, you have a double leading slash, which is not a valid path format.

 

Specifically, you're supplying the path "/Applicazioni/Costumer Manager Files/Ore.txt", but then are adding an extra leading slash when you format it with your code:

$TargetFilePath="/$testFile"

 

lucaortis
Explorer | Level 4

I found this very confusing but I managed to solve it like this: 

 

 

 $testFile = Split-Path $SourceFilePath -leaf
 $TargetFilePath="/$testFile"
 $arg = '{"path": "' + $TargetFilePath + '"}'

 

 

 

I know it works, but I'm really confused on how the path itself works. 
Upload and download code to format PATH are now the same as this. 


Thank you!!

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    lucaortis Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?