Forum Discussion

Priya M.'s avatar
Priya M.
Explorer | Level 4
8 years ago

Dropbox API for search in PHP

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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,943 PostsLatest Activity: 2 hours ago
351 Following

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!