We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
chip -.
10 years agoNew member | Level 1
Powershell-Download not working api v2
Hi,
I want to download with powershell a file from the dropbox.But I always get a 400 error.
$arg = '{"path": "/'+$SourceFilePath+'.txt"}'
$authorization = "Bearer <access token>"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $authorization)
$headers.Add("Dropbox-API-Arg", $arg)
Invoke-RestMethod -Uri https://content.dropboxapi.com/2/files/download -Method Post -Headers $headers -OutFile $SourceFilePath
My upload script works perfectly:
$arg = '{"path": "/'+$DestinationFilePath+'.txt","mode": "overwrite", "autorename": false, "mute": false }'
$authorization = "Bearer <access token>"
$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://api-content.dropbox.com/2/files/upload -Method Post -InFile $SourceFilePath -Headers $headers
Can anyone tell me what's wrong with the download part?
7 Replies
Replies have been turned off for this discussion
- Greg-DB10 years ago
Dropbox Community Moderator
What does the body of the 400 response show? It should be an error indicating the issue.
- chip -.10 years agoNew member | Level 1
In the body are: "Bad Request".
- Greg-DB10 years ago
Dropbox Community Moderator
That's just the status. Check the body of the response for more information.
- chip -.10 years agoNew member | Level 1
Ok the body say: "Error in call to API function "files/download": You provided a non-empty HTTP "Content-Type" header ("application/x-www-form-urlencoded"). This API function requires that the header be missing or empty."
But if I extend the header ($headers.Add("Content-Type", 'application/x-www-form-urlencoded')) as is still the exact same error.
- Greg-DB10 years ago
Dropbox Community Moderator
The message says that the API call expects a missing or empty Content-Type, and that you provided 'application/x-www-form-urlencoded', not that you should provide it.
You should instead make sure you don't send a Content-Type header at all, or if you do, make sure it's empty.
- Greg-DB10 years ago
Dropbox Community Moderator
I haven't tried it myself, but it looks like you may need to use -ContentType ''.
- chip -.10 years agoNew member | Level 1
Thank you Gregory, this fix my problem.
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!