<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Delete Folder Using PowerShell in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303070#M18310</link>
    <description>&lt;P&gt;Can 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.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Oct 2018 15:08:01 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2018-10-15T15:08:01Z</dc:date>
    <item>
      <title>Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/302667#M18295</link>
      <description>&lt;P&gt;I can't figure out how to delete a file in my Dropbox using Powershell. I can upload fine using this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$arg = '{ "path": "' + $TargetFilePath + '", "mode": "add", "autorename": true, "mute": false }'
$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/octet-stream')

Invoke-RestMethod -Uri https://content.dropboxapi.com/2/files/upload -Method Post -InFile $SourceFilePath -Headers $headers&lt;/PRE&gt;&lt;P&gt;But I don't now how to use "&lt;A href="https://api.dropboxapi.com/2/files/delete_v2" target="_blank"&gt;https://api.dropboxapi.com/2/files/delete_v2&lt;/A&gt;" even after reading the documentation (I'm not a developer so this is new to me).&lt;/P&gt;&lt;P&gt;I used the&amp;nbsp;Dropbox API Explorer • delete_v2 to generate the code for a curl request which works from the Dropbox API Explorer but I'd like to use PowerShell in the same way I do for uploading. The working curl request is:&lt;/P&gt;&lt;PRE&gt;curl -X POST https://api.dropboxapi.com/2/files/delete_v2 \
  --header 'Authorization: Bearer &amp;lt;access-token&amp;gt;' \
  --header 'Content-Type: application/json' \
  --data '{"path":"/20181009"}'&lt;/PRE&gt;&lt;P&gt;Can anyone tell me how to use "Invoke-RestMethod -Uri &lt;A href="https://api.dropboxapi.com/2/files/delete_v2" target="_blank"&gt;https://api.dropboxapi.com/2/files/delete_v2&lt;/A&gt;" in PowerShell similar to the upload method above to delete a folder? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:09:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/302667#M18295</guid>
      <dc:creator>D-B</dc:creator>
      <dc:date>2019-05-29T09:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/302729#M18299</link>
      <description>&lt;P&gt;Using the&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-delete" target="_blank"&gt;/2/files/delete_v2&lt;/A&gt; endpoint is the right way to delete a folder. Calling it will be similar to&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload" target="_blank"&gt;/2/files/upload&lt;/A&gt;, but&amp;nbsp;with some important differences.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload" target="_blank"&gt;/2/files/upload&lt;/A&gt;&amp;nbsp;endpoint is &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#content-upload-endpoints" target="_blank"&gt;a "content-upload" endpoint&lt;/A&gt;, so it takes the parameters as JSON in the "Dropbox-API-Arg" header.&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-delete" target="_blank"&gt;/2/files/delete_v2&lt;/A&gt;&amp;nbsp;endpoint is &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#rpc-endpoints" target="_blank"&gt;an "RPC" endpoint&lt;/A&gt;&amp;nbsp;though, so it takes the parameters as JSON in the request body.&lt;/P&gt;
&lt;P&gt;If you have code for &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-delete" target="_blank"&gt;/2/files/delete_v2&lt;/A&gt; that doesn't seem to be working, print out the response body you get when you call it. If the call isn't working, there should be an error message in the response body. (You may need to add some extra code to print that out, e.g., &lt;A href="https://stackoverflow.com/questions/18771424/how-to-get-powershell-invoke-restmethod-to-return-body-of-http-500-code-response" target="_blank"&gt;as shown in this post&lt;/A&gt;.)&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 15:32:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/302729#M18299</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-10-12T15:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/302999#M18306</link>
      <description>&lt;P&gt;Thank you for your reply, sorry that I don't understand everything you have explained here, this is the first time I've attempted anything like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The best I could do is to take the working upload code and change it to the below which isn't correct but the closest I could get to what I thought it should be. It seems that my&amp;nbsp;Invoke-RestMethod command parameters are wrong and probably the headers too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$TargetFilePath = "/20181008"
$DropBoxAccessToken = "&amp;lt;access-token&amp;gt;"

$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')
 
Invoke-RestMethod -Method Delete -Uri https://api.dropboxapi.com/2/files/delete_v2 -Headers $headers&lt;/PRE&gt;&lt;P&gt;Here is the output after the PowerShell script fails:&lt;/P&gt;&lt;PRE&gt;Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At (SCRIPT LOCATION)\Dropbox-Delete.ps1:12 char:1
+ Invoke-RestMethod -Method Delete -Uri https://api.dropboxapi.com/2/fi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 10:25:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/302999#M18306</guid>
      <dc:creator>D-B</dc:creator>
      <dc:date>2018-10-15T10:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303070#M18310</link>
      <description>&lt;P&gt;Can 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.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 15:08:01 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303070#M18310</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-10-15T15:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303241#M18326</link>
      <description>&lt;P&gt;I just tried adding the code from each answer in that post but I get no output from PowerShell at all.&lt;/P&gt;&lt;P&gt;First one I tried:&lt;/P&gt;&lt;PRE&gt;$TargetFilePath = "/20181008"
$DropBoxAccessToken = "&amp;lt;access-token&amp;gt;"

$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 }&lt;/PRE&gt;&lt;P&gt;Second:&lt;/P&gt;&lt;PRE&gt;$TargetFilePath = "/20181008"
$DropBoxAccessToken = "&amp;lt;access-token&amp;gt;"

$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();
}&lt;/PRE&gt;&lt;P&gt;I must be formatting this wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 09:32:10 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303241#M18326</guid>
      <dc:creator>D-B</dc:creator>
      <dc:date>2018-10-16T09:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303345#M18331</link>
      <description>&lt;P&gt;I believe your second version is closer, as it actually reads the body. (The first one doesn't appear to.)&lt;/P&gt;
&lt;P&gt;In both though, you're not actually printing out the result or saving it anyway. E.g., something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Write-Output $responseBody&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 15:24:55 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303345#M18331</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-10-16T15:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303355#M18333</link>
      <description>&lt;P&gt;I get output now, thanks.&lt;/P&gt;&lt;PRE&gt;Your request's HTTP request method is "DELETE", which is not supported by the Dropbox API v2.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 16:00:28 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303355#M18333</guid>
      <dc:creator>D-B</dc:creator>
      <dc:date>2018-10-16T16:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303380#M18335</link>
      <description>&lt;P&gt;That output indicates that the issue is that you're using the "DELETE" method, which isn't allowed. The API expect the "POST" method.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's presumably due to the "-Method Delete" in your code; for POST you would likely need to set "-Method Post".&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 17:01:11 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303380#M18335</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-10-16T17:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303504#M18340</link>
      <description>&lt;P&gt;This is the response when I changed Delete to Post.&lt;/P&gt;&lt;PRE&gt;Error in call to API function "files/delete:2": Unexpected HTTP headers: "Dropbox-Api-Arg"&lt;/PRE&gt;&lt;P&gt;When removing the line $headers.Add("Dropbox-API-Arg", $arg) the response is:&lt;/P&gt;&lt;PRE&gt;Error in call to API function "files/delete:2": request body: could not decode input as JSON&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 08:23:11 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303504#M18340</guid>
      <dc:creator>D-B</dc:creator>
      <dc:date>2018-10-17T08:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Folder Using PowerShell</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303585#M18342</link>
      <description>&lt;P&gt;That is also expected, as this endpoint requires the parameters be sent as JSON in the request body. Please refer to &lt;A href="https://www.dropboxforum.com/t5/API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/302729/highlight/true#M18299" target="_blank"&gt;my earlier comment&lt;/A&gt; for links to documentation&amp;nbsp;for this.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 15:43:06 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Delete-Folder-Using-PowerShell/m-p/303585#M18342</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-10-17T15:43:06Z</dc:date>
    </item>
  </channel>
</rss>

