Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
heisenberg41
6 years agoNew member | Level 2
Bad HTTP "Content-Type" header
Hello,
I am writing a simple app that creates some folders when we add a new client to our systems.
I keep getting an error:
Error in call to API function "files/create_folder_batch": Bad HTTP ...
Greg-DB
Dropbox Community Moderator
6 years agoIt looks like you're just passing along a native object as the API call parameters, and curl is then applying the multi-part Content-Type. You should send up the parameters as JSON.
You can build your parameters as JSON like:
$params = json_encode(array(
'paths'=> $folders,
'autorename'=> false,
'force_async'=> false));- heisenberg416 years agoNew member | Level 2
Thank you Greg! That worked.
Biggest noob question of all. How did you know it had to be JSON encoded?
- Greg-DB6 years ago
Dropbox Community Moderator
Great, thanks for confirming that.
All Dropbox API v2 endpoints (except OAuth endpoints) expect the parameters as JSON, though there are some different ways of sending them. You can find information about each one in the documentation. For example, the /2/files/create_folder_batch endpoint uses the "RPC" format, so it expects "JSON in the request body and return results as JSON in the response body".
- eranga1196 years agoNew member | Level 2
Error in call to API function "sharing/create_shared_link_with_settings": Bad HTTP "Content-Type" header: "application/json{\"path\":\"\\/1uawro.jpg\",\"settings\":{\"requested_visibility\":\"public\",\"audience\":\"public\",\"access\":\"viewer\"}}". Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack".
$share_link = array("path"=> $path, "settings"=> array("requested_visibility"=> "public", "audience"=> "public", "access"=> "viewer"));
$share_link_url = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings";
$headers = array('Authorization: Bearer '. $token,
'Content-Type: application/json'.
json_encode($share_link)
);i was encoded but not work for me.plz advice
- Greg-DB6 years ago
Dropbox Community Moderator
eranga119 This error message indicates that instead of just sending the expected "application/json" value in your "Content-Type" header, you're instead sending that plus the JSON string for the API call parameters, as Здравко said. That JSON should be sent in the request body, not a header.
The code you shared does seem to show you are incorrectly appending those parameters to your "Content-Type" header value, so you should fix your code to put that in the request body instead.
- eranga1196 years agoNew member | Level 2
@greg-DB thank you for quick responce.i was fix my code and it's work perfectly now. you are abslutly correct.
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!