One month down in 2025: How are your resolutions coming along? Check out how to get back on track 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
- Greg-DB
Dropbox Staff
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 & Feedback
Find help with the Dropbox API from other developers.5,941 PostsLatest Activity: 22 hours ago
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!