Skip to main content

I am using an App Token as my authentication and I am attempting to find a file by its name by submitting a cURL request to /search?query={filename}&type=file. While the response is successful in both my PHP code and doing it from the terminal, nothing is ever returned.



Is there something I’m missing?



For what its worth, here is my PHP function:



function findRecordByFilename($accessToken, $filename) {

$encodedFileName = urlencode($filename);

$curl = curl_init();



curl_setopt_array($curl, ,

CURLOPT_URL => "https://api.box.com/2.0/search?query=$encodedFileName&type=file",

CURLOPT_RETURNTRANSFER => true,

CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

CURLOPT_CUSTOMREQUEST => "GET",

CURLOPT_HTTPHEADER => ;

"authorization: Bearer $accessToken"

],

]);



$response = curl_exec($curl);

$curlError = curl_error($curl);



curl_close($curl);



// do something meaningful here, this is just an example

if ($curlError) {

echo '<pre><code>' . json_decode($curlError) . '</code></pre>';

} else {

echo json_decode($response, true);

}

}



And this is the raw cURL request I’m calling from Git BASH:



curl -X GET "https://api.box.com/2.0/search?query=redacted.jpg&type=file" -H "authorization: Bearer redacted"



Edit - I forgot to mention that I followed the steps to create an App Token here https://developer.box.com/guides/authentication/app-token/app-token-setup and I am passing the access token as the bearer token.

Hi @dday9



If the file you are searching was recently created it might not have been indexed yet.



It can take 15 minutes for the file to be indexed.



Another possibility is that the user associated with the app token does not have access to the file, so it wont show up in the search.



Let us knwo if this helps



Best regards


Reply