cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issue in get preview api v2

Issue in get preview api v2

ashoka
New member | Level 2

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 1

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'.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?