You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

VijayKumar E's avatar
VijayKumar E
Explorer | Level 3
3 years ago

Bad HTTP "Content-Type" header from the Dropbox API

When I try a request to Dropbox API(v2), I am getting this error ,

 

"message": "Error in call to API function  "users/get_current_account": Bad HTTP "Content-Type\" header: "application/x-www-form-urlencoded". Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack"

 

I am referring the following DropBox Documentation link  and setting the Header as mentioned .  Can someone please

help what is the reason for the issue ?

 

I am getting the above error message for the following APIs 

 

/users/get_space_usage

 

users/get_current_account

 

  • Здравко's avatar
    Здравко
    Legendary | Level 20

    Hi VijayKumar E,

    The error message is descriptive enough, I think. For most API calls data are transferred in JSON form, not in urlencoded one. Seems you are trying to pass something in incorrect form. Even more, neither '/users/get_space_usage' nor '/users/get_current_account' require any parameters, so what are you actually trying to pass?! 🤔 In both cases authentication information would be enough. It's not an API call parameter, but independent header entry!

    Try to post some code snippet reproducing the issue or raw HTTP headers for more details.

     

    PS: May be useful try Dropbox API Explorer for get_current_account (for example). Click 'Show Code' button and select 'HTTP request' to see what has to be. 😉

    • VijayKumar E's avatar
      VijayKumar E
      Explorer | Level 3

      Hi ,

      For the mentioned APIs '/users/get_space_usage' and '/users/get_current_account' I am not sending any data in the request. So why should I set the content-type as application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack" for the request ?

      In both cases we are just passing the authentication information by referring DropBox Documentation .

      By seeing the error message I tried the APIs by setting those content-type as application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack" but still it was not working .

      When I tried the API by passing the content-type as empty string ( Content-Type : “” ) it’s working fine.

      • Здравко's avatar
        Здравко
        Legendary | Level 20

        VijayKumar E wrote:

        ... So why should I set the content-type as application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack" for the request ? ....


        You shouldn't set anything, actually.

         


        VijayKumar E wrote:

        ...
        When I tried the API by passing the content-type as empty string ( Content-Type : “” ) it’s working fine.


        Great! 👍 Seems you have found it. Maybe that's the way in your environment to disable content-type header sending together with empty query body. 🤷

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Здравко is correct, it looks like your code/client is just sending the wrong "Content-Type" request header, and these endpoints don't take any parameters, so that header isn't required anyway. You mentioned you are attempting to set the header correctly, but it's possible whatever HTTPS client you're using is overriding that. You may need to refer to the documentation for your client for information on configuring it accordingly.

  • humanclock's avatar
    humanclock
    New member | Level 2

    Yes, for anyone reading this...

     

    If you are calling something that takes no parameters like: https://api.dropboxapi.com/2/users/get_current_account

     

    you need to make sure either you:

    1) Explicitly send NO Content-type header with your request so it is completely absent:

     

    or

     

    2) If you have an underlying framework in your code making the call that puts in a default content header, you need to explicitly override it and send a blank one ala Content-type: "" 

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 12 months ago
325 Following

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 or Facebook.

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!