Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
ashoka
7 years agoNew member | Level 2
Issue in get preview api v2
Error in call to API function "files/get_preview": The request body is supposed to be empty, but it isn't; got "{\"path\":\"\\/2019_DB\\/Copies\\/A123\\/NEW\\/21004_1910036125.pdf\"}"
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $auth_token, "Content-Type : application/x-www-form-urlencoded"));
//curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings");
//curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/files/get_temporary_link");
curl_setopt($ch, CURLOPT_URL, "https://content.dropboxapi.com/2/files/get_preview");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('path'=> $file_path)));
$result = curl_exec($ch);
print_r($result);
I tried with content-type : application:pdf as well
I want to view file in browser or iframe
1 Reply
- Greg-DB7 years ago
Dropbox Community Moderator
This error message is indicating that you're supply a request body with this API call, but the API expects the request body to be empty.
That's expected per the documentation for /2/files/get_preview, which indicates that it's a "Content-download" style endpoint. The documentation there covers this in more detail, but in short, you should be sending the API call parameters in a 'Dropbox-API-Arg' header, not the request body.
To fix this, update your code to send the parameters in a 'Dropbox-API-Arg' header, instead of in the request body, as you're currently doing with 'CURLOPT_POSTFIELDS'.
About Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.
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!