<?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: Powershell File Upload - Bad Request in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Powershell-File-Upload-Bad-Request/m-p/480554#M24246</link>
    <description>&lt;P&gt;I'm glad to hear you already sorted this out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For future reference, or for anyone else in a similar scenario, make sure you read out the response body, as it will generally contain a more specific error message which can help you debug issues like this. It sounds like PowerShell doesn't show that by default, but you can read it as described in &lt;A href="https://github.com/MicrosoftDocs/PowerShell-Docs/issues/4456" target="_self"&gt;this thread&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Dec 2020 15:45:44 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2020-12-18T15:45:44Z</dc:date>
    <item>
      <title>Powershell File Upload - Bad Request</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Powershell-File-Upload-Bad-Request/m-p/466227#M23787</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First off, I did search the forums. &lt;A href="https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Upload-Files-Function-Powershell-Bad-Request/m-p/249576" target="_self"&gt;This post&amp;nbsp;&lt;/A&gt;, titled the same as this help request, seemed similar but was not helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following simple curl upload working fine:&lt;/P&gt;
&lt;PRE&gt;curl -X POST https://content.dropboxapi.com/2/files/upload \
    --header "Authorization: Bearer MyKeyGoesHereButThisIsNotReallyIt" \
    --header "Dropbox-API-Arg: {\"path\": \"/test.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}" \
    --header "Content-Type: application/octet-stream" \
    --data-binary @test.txt&lt;/PRE&gt;
&lt;P&gt;And this is that same request converted to powershell - as you can see, I'm using the same API args.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;$arg = '{ "path": "test.txt", "mode": "add" "autorename": true, "mute": false, "strict_conflict:" false }'
$authorization = "Bearer MyKeyGoesHereButThisIsNotReallyIt"

$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')
 
$response = Invoke-RestMethod -Uri https://content.dropboxapi.com/2/files/upload -Method Post -InFile test.txt -Headers $headers&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I'm getting back Error 400, Bad Request.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is this throwing a bad request error? I'm trying with the same args in both, same file to upload, but with Powershell, I just get this error. I'm not making any changes to the app between the two.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Nov 2020 12:13:33 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Powershell-File-Upload-Bad-Request/m-p/466227#M23787</guid>
      <dc:creator>Phydeaux</dc:creator>
      <dc:date>2020-11-03T12:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell File Upload - Bad Request</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Powershell-File-Upload-Bad-Request/m-p/466559#M23797</link>
      <description>&lt;P&gt;Can you print out the response body for the call made by the&amp;nbsp;PowerShell code? It should contain a more useful error message indicating what the issue is in that case.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 15:49:14 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Powershell-File-Upload-Bad-Request/m-p/466559#M23797</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-11-02T15:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell File Upload - Bad Request</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Powershell-File-Upload-Bad-Request/m-p/480444#M24239</link>
      <description>&lt;P&gt;Hey, I know i'm necroing this thread, but I'm in the exact same situation as OP, and hope you've somehow seen and solved other cases since.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Works fine in insomnia, but powershell refuses to cooperate.&lt;/P&gt;&lt;P&gt;Ive put it in a try catch, but there is no info in the exception what so ever.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&lt;/P&gt;&lt;P&gt;As always, the solution comes after you asked someone for help.&lt;/P&gt;&lt;P&gt;I had not considered that the target path and filename was not in quotes, so the json was wrong. I use arguments in azure pipelines, so it eluded me completely.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ended up with this:&lt;/P&gt;&lt;PRE&gt;$targetPathAndFilename = ' "/Folder/file.exe" '

$arg = '{ "path": '+$targetpathAndFilename+', "mode": "add", "autorename": true, "mute": false }'&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 10:22:06 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Powershell-File-Upload-Bad-Request/m-p/480444#M24239</guid>
      <dc:creator>Heinek</dc:creator>
      <dc:date>2020-12-18T10:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell File Upload - Bad Request</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Powershell-File-Upload-Bad-Request/m-p/480554#M24246</link>
      <description>&lt;P&gt;I'm glad to hear you already sorted this out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For future reference, or for anyone else in a similar scenario, make sure you read out the response body, as it will generally contain a more specific error message which can help you debug issues like this. It sounds like PowerShell doesn't show that by default, but you can read it as described in &lt;A href="https://github.com/MicrosoftDocs/PowerShell-Docs/issues/4456" target="_self"&gt;this thread&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 15:45:44 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Powershell-File-Upload-Bad-Request/m-p/480554#M24246</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-12-18T15:45:44Z</dc:date>
    </item>
  </channel>
</rss>

