Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi,
I'm trying to search for a file uploaded in my Dropbox APP using the following code:
$data = json_encode(array("path" => "/", "query" => $this->filename, "mode" => "filename")); $url = 'https://api.dropboxapi.com/2/files/search'; $headers = array('Authorization: Bearer '.$GLOBALS['access_token'], 'data: '.$data, 'Content-Type: application/json'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_PUT, true); // Turn off the server and peer verification (TrustManager Concept). curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Get response from the server. $resp = curl_exec($ch); echo '<br />Curl Response: '; print_r($resp); curl_close($ch);
I'm getting the curl response as:
Error in call to API function "files/search": request body: could not decode input as JSON
Please tell me what correction needs to be done.
Looking over your code, there are a few things that should be fixed:
- When specifying the root folder, you need to use the empty string "", not "/".
- You'll need to POST (CURLOPT_POST) not PUT (CURLOPT_PUT).
- You should not turn off SSL verification if possible.
- The parameters must be passed as JSON in the HTTP request body, not in a header.
You can find more information on using this endpoint here:
https://www.dropbox.com/developers/documentation/http/documentation#files-search
There's an example of calling an "RPC" endpoint like this in PHP here:
Hi,
Thank you for your reply. I was able to do that. Removing CURLOPT_PUT resolved the issue.
I have now issues with reading the files uploaded on dropbox. I can see that the endpoint for this purpose is : https://www.dropbox.com/developers/documentation/http/documentation#files-download
I'm not able to understand how to use the output of the above API to read instead of saving the file locally?
Hi,
Thank you for your reply.
We do not want to save in local file. Also, reading in memory may cause memory exhausted issue with large files. Same is the issue with saving the read data in a variable when the file is large enough.
Instead, we want to read the file in parts instead of reading the entire file at once. Is there any option to the same?
Thanks for your response.
I will do the PHP part myself. I got confused by your incorrect reply previously and started searching more in that direction.
Thanks again for your help.
Hi there!
If you need more help you can view your support options (expected response time for a 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!