Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
D-B
8 years agoExplorer | Level 3
Delete Folder Using PowerShell
I can't figure out how to delete a file in my Dropbox using Powershell. I can upload fine using this : $arg = '{ "path": "' + $TargetFilePath + '", "mode": "add", "autorename": true, "mute": fals...
Greg-DB
Dropbox Community Moderator
8 years agoCan you print the response body as mentioned/linked in my last post? You'll want to retrieve the error message from it to debug things like this.
D-B
8 years agoExplorer | Level 3
I just tried adding the code from each answer in that post but I get no output from PowerShell at all.
First one I tried:
$TargetFilePath = "/20181008"
$DropBoxAccessToken = "<access-token>"
$arg = '{ "path": "' + $TargetFilePath + '" }'
$authorization = "Bearer " + $DropBoxAccessToken
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $authorization)
$headers.Add("Dropbox-API-Arg", $arg)
$headers.Add("Content-Type", 'application/json')
$resp = try { Invoke-RestMethod -Method Delete -Uri https://api.dropboxapi.com/2/files/delete_v2 -Headers $headers } catch { $_.Exception.Response }Second:
$TargetFilePath = "/20181008"
$DropBoxAccessToken = "<access-token>"
$arg = '{ "path": "' + $TargetFilePath + '" }'
$authorization = "Bearer " + $DropBoxAccessToken
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $authorization)
$headers.Add("Dropbox-API-Arg", $arg)
$headers.Add("Content-Type", 'application/json')
try {
$result = Invoke-RestMethod -Method Delete -Uri https://api.dropboxapi.com/2/files/delete_v2 -Headers $headers
}
catch {
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
}I must be formatting this wrong?
- Greg-DB8 years ago
Dropbox Community Moderator
I believe your second version is closer, as it actually reads the body. (The first one doesn't appear to.)
In both though, you're not actually printing out the result or saving it anyway. E.g., something like:
Write-Output $responseBody
- D-B8 years agoExplorer | Level 3
I get output now, thanks.
Your request's HTTP request method is "DELETE", which is not supported by the Dropbox API v2.
- Greg-DB8 years ago
Dropbox Community Moderator
That output indicates that the issue is that you're using the "DELETE" method, which isn't allowed. The API expect the "POST" method.
That's presumably due to the "-Method Delete" in your code; for POST you would likely need to set "-Method Post".
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!