Forum Discussion

chip -.'s avatar
chip -.
New member | Level 1
10 years ago

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-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    What does the body of the 400 response show? It should be an error indicating the issue.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    That's just the status. Check the body of the response for more information.

  • chip -.'s avatar
    chip -.
    New member | Level 1
    10 years ago

    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-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    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.

About Dropbox API Support & Feedback

Node avatar for 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!