SUCCESSFUL RESPONSE BUT CANT RETRIEVE INNER FOLDERS & DOCUMENTS - PLEASE HELP ASAP!!

  • 1
  • Problem
  • Updated 6 months ago
We are getting a successful response after calling the API in PHP with your HTTP method. However within the Personal Folders we have the folders showing with no documents. And in the Shared Folders we have no Folders and no documents showing. Can you please review our Code where we are calling the ITEM ID by your LINK for GET ITEM BY ID ?? We really would appreciate your support please please help us. Our client has a pretty big account with you guys and must have this integrated.



function get_item_by_id($token, $item_id) {
   // $uri = "https://".get_hostname($token)."/sf/v3/Items(".$item_id.")";
    $uri = "https://".get_hostname($token)."/sf/v3/Items(".$item_id.")/Children";

//https://account.sf-api.com/sf/v3/Items(id)/Children

    echo "GET ".$uri."\n";
 
    $headers = get_authorization_header($token);
 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $uri);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
    $curl_response = curl_exec ($ch);
 
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $curl_error_number = curl_errno($ch);
    $curl_error = curl_error($ch);
 
    //echo $curl_response."\n"; // output entire response
    echo $http_code."\n"; // output http status code
     
    curl_close ($ch);
 
    $root = json_decode($curl_response);
    //print_r($root); // print entire json response
    echo $root->Id." ".$root->CreationDate." ".$root->Name."\n";
}
 


$item=get_item_by_id($token,'fohd08e9-3403-4d45-a31d-48b0869b6a0d');
 
 echo " <h1>Item Details</h1> -- <pre>";
 print_r($item);
 echo "</pre>";
 
// echo "Users <pre>"; print_r($users);
 //https://".$this->get_hostname($token)."/sf/v3/Items(".$folder_id.")/Upload&am...
// https://account.sf-api.com/sf/v3/Shares
// exit;

/* echo" All -- <pre>";
print_r($token);
echo "</pre>";  */

if($token) {
    get_root($token, TRUE);
}
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes

Posted 7 months ago

  • 1
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 52 Posts
  • 7 Reply Likes
Please see the Download call documentation here https://api.sharefile.com/rest/docs/resource.aspx?name=Items
Depending on what you set the "redirect" url parameter to (true/false), the API will either:
1) For redirect=true; respond with a 302 redirect response and redirect you to the download link. 
2) For redirect=false; return a download url in the response content. It's then up to you to download the file from this new url.


Also, at a glance you seem to be passing four parameters to the "download_item" when it only takes three:

download_item($token, 'fi433fe6-9ee3-b76a-61ea-7b80fd69dd53',$_GET['download'], $local_path='C:\Users\murali\Downloads');
(Edited)
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi Thanks for you help but i am still not able to download the files please check my download function

function download_item($token, $item_id, $local_path) {
  
     $uri= "https://".get_hostname($token)."/sf/v3/Items(".$item_id.")/Download?includeallve...;
$fp = fopen($local_path, 'w');   
     $headers = get_authorization_header($token);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $uri);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
     curl_setopt($ch, CURLOPT_FILE, $fp);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     $curl_response = curl_exec($ch);
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $curl_error_number = curl_errno($ch);
     $curl_error = curl_error($ch);
     echo $http_code."\n";
     curl_close($ch);
     fclose($fp);
 }

i am getting  200 status only. file is not downloading... Please let me know as soon as possible.
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 52 Posts
  • 7 Reply Likes
Your code works fine for me. 200 is returned, and the file "$local_path" is created with the expected file contents in it.
Please make sure you're calling the download_item function with the proper number and correct parameters. Also, you might want to double check that you can access whatever location you are trying to save to.

Also, $local_path has to point to a file, and not a directory.
So $local_path='C:\Users\murali\Downloads' won't work, but $local_path='C:\Users\murali\Downloads\<FileName>.<extension>" will.
(Edited)