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

  • 1
  • Problem
  • Updated 3 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 4 months ago

  • 1
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
Hi Vick,

The "get_item_by_id" call only gets the metadata of an item.
The "get_folder_with_query_parameters" call can be used to get an item's children.

If that doesn't do it, can you paste in the exact urls you're calling out to with their exact output?

Luke
(Edited)
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi Luke Skrzypek,

Thank you for reply.

I am getting below issues while calling api

1. I am unable to get "Shared folder  and child folders"

2.I am getting "personal folder and child folders" but cant access files in child folder.

Those two are my issues. I have provided my code below please check it once.

function authenticate($hostname, $client_id, $client_secret, $username, $password) {
    $uri = "https://".$hostname."/oauth/token";

   //echo "POST ".$uri."\n";
 
    $body_data = array("grant_type"=>"password", "client_id"=>$client_id, "client_secret"=>$client_secret,
                  "username"=>$username, "password"=>$password);
    $data = http_build_query($body_data);
     
    $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_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/x-www-form-urlencoded'));
 
    $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);
    $token = NULL;
//echo "<br> Print value -".$http_code; echo "<br/> After Value ";
    if ($http_code == 200) {
        $token = json_decode($curl_response);
        //print_r($token); // print entire token object
    }
//echo " <br> ".$token; exit;
    return $token;
}

function get_folder_with_query_parameters($token, $item_id) {
    $uri = "https://".get_hostname($token)."/sf/v3/Items(".$item_id.")?\$expand=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
     
    // only Id, Name are available here, because thats all that was requested
    echo $root->Id." ".$root->Name." "."\n";
    if (property_exists($root, "Children")) {
        foreach($root->Children as $child) {
            echo $child->Id." ".$child->CreationDate." ".$child->Name."\n";
        }
    }
}
 


 
$token = authenticate($hostname, $client_id, $client_secret, $username, $password);

$item=get_folder_with_query_parameters($token,'fohd08e9-3403-4d45-a31d-48b0869b6a0d');
 
 echo " <h1>Item Details</h1gm> -- <pre>";
 print_r($item);
 echo "</pre>";
 
---------------------------------------------------------------------------------------------------

please check it once.
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
Hi Vick,

Your code seems fine, and runs as expected. 
Are you trying to get all the items in your account? Expanding the children of a folder will only get you the direct children of that item (in this case your personal home folder; fohd08e9-3403-4d45-a31d-48b0869b6a0d)

To get all the children and sub-children in a folder, you'll need to make the children call for each subfolder (going as deep as necessary).

The same goes for your shared folders. The top level shared folders can be accessed by calling get_folder_with_query_parameters on the "allshared" item id, but you'll need to call it again on its children to drill down deeper.
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Thank You very much. We are working on this right away and will get back to you very soon. Please check our thread in a few hours. 
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi Luke Skrzypek,

Thank you for your valuable reply.

I am getting child folder files. But my requirement is user level folder access. Depending on user should access his files or folders only. So please tell me how can i get it.
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
If you're looking for a specific user's personal file and folders, you can get the children of their home folder, and then go as deep as necessary getting children of the various sub-folders.
To get the home folder of a specific user, you can use the GET https://account.sf-api.com/sf/v3/Users(id)/HomeFolder API.

If you're looking for all the files and folders a user has access to (both their personal, and shared folders they have been added to), there is no straight-forward way of doing that without authenticating as the user themselves.
Once you've authenticated as a given user you can start at the top level (by querying the 'top' folder id for children) and go from there.
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi Luke,

while calling the above url i am getting authentication fail error. i have provided my code below please check it.

function get_user_root($token, $user='',$get_children=TRUE) {
     // $uri = "https://".get_hostname($token)."/sf/v3/Items";
  $uri = "https://".get_hostname($token)."/sf/v3/Users(d922042e-5d1e-4786-a934-30809b710eec)/HomeFol...;

    if ($get_children == TRUE) {
        $uri .= "?\$expand=Children";
    }
    $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);

echo "hai---<pre>";
    print_r($root); // print entire json response
echo "</pre>";
exit; 
     
   // echo $root->Id." ".$root->CreationDate." ".$root->Name."\n";

    if (property_exists($root, "Children")) {
        foreach($root->Children as $child) {
            //echo $child->Id." ".$child->CreationDate." ".$child->Name."\n";
$child_data=get_folder_with_query_parameters($token,$child->Id);

echo " hello hello <pre>";print_r($child_data); echo "</pre>";
 
        }
    }
 }

$token = authenticate($hostname, $client_id, $client_secret, $username, $password);

$data=get_user_root($token); 
 

Note : here user id is d922042e-5d1e-4786-a934-30809b710eec i know the user id so i have passed directly.

please let me know what is issue.
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
I'm assuming you mean the /sf/v3/Users(d922042e-5d1e-4786-a934-30809b710eec)/HomeFolder call is failing.

You need to make sure that the user you're authenticating as (in the authenticate call) has permissions to access the second user's (d922042e-5d1e-4786-a934-30809b710eec) home folder (i.e an admin account), and that the second user is an employee (as client users don't have home folders)
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi Luke,

           Thanks for your response i will check it and let you know as soon as possible.
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
HI Luck,

I have mentioned my requirement below. Please check it and give me once solution,

1.i need user level folder/file  access in to my website.


I have an shared folder account  ( https://devilleltd.sharefile.com).  my admin account having below folders,


 personal --> xxxxx folder
 shared folder --> aaaaaaa folder --> abc folder --> file one .......etc
                       --> bbbbbbb folder
                      ---> ccccccc  folder

This is my folder structure. I have created some users folder wise in shared folder. Now i want to access those folders user wise in to my web application. This is my requirement.

As per your previous conversation  "second user is an employee (as client users don't have home folders)"

Now Please tell me how can i access those files or folders in to my website by user wise.
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
You can access the entire list of shared folders by querying the children of the "allshared" item.
For a shared folder created by another user (user2) to be visible to you, your user (user1) either 1) has to be a member of the "Super Users" group or 2) be explicitly added to the folder permissions of the folder.

Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi Luke,

i am unable to understand what you are trying to say. I have explained my requirement clearly. 
If it is possible please provide your contact number.so that we can close this with in 30 min. This is going from past 2 weeks. So please provide your contact number.

if it is not possible please send code for  accessing folders inside shared folders by user wise. i am able to see all items of users/folders inside of shared folder i had explained to you previously.

Please guide me to finish the API integration with my web portal.


Thanking you.
(Edited)
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
I'm sorry, but it's not clear as to what you're asking for.

1) If you need to see all the shared folders a user has access to you can use either the "https://account.sf-api.com/sf/v3/Items(allshared)/Children" api or "https://account.sf-api.com/sf/v3/Users/AllSharedFolders".
This will get you the top level shared folders that the user you authenticated as has access to. It's then possible to drill down into them with further "/Children" calls.

So, in your example, if you call either API while logged in as an admin user, you should get back the "aaaaaaa", "bbbbbbb", and "ccccccc" folders.
You can then call the "/Children" API repeatedly on each folder's ID to get their subfolders and files.

If you're authenticated as an admin super user, this should include all top level shared folders in your account.
If the user that you logged in as is not in the "super user" group, then you'll only be able to see the shared folders that they have access to.

2) If you're trying to see all the shared folders a user (user2) has access to while authenticated as another user (admin1), then I don't believe this is currently possible with the API.
You would need to authenticate with the api as the user (user2) to see the items they specifically have access to.


Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi Luke,

           Thanks for your response i will check it and let you know as soon as possible.
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi Luke,

by using https://account.sf-api.com/sf/v3/Users/AllSharedFolders this api i am getting all shared folders and if i drill the folder i am getting the child folder also. But the issue is  i am login in to one user account in my website. So i have to access my shared folders only. here i am getting all users folders and files. So please give me user level restriction api. so that i can restrict the user.

thanking you.
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
The "AllSharedFolders" call will return all top level shared folders the user you authenticated as has access to (whether that be because you're the owner, or the folder is shared with you). If a folder appears in these results, it's because your user has at least some sort of access to it.
You can expand the "Owner" or "Creator" properties on the folder (or check the "CreatorFirstName" and "CreatorLastName") to check which of these folders your user is the owner/creator of.

To my knowledge, the API does not offer a way to get all your owned/created shared folders at once.

To check the shared folders another user has access to, you would need to authenticate as them with the API, and then do the AllSharedFolders call again. (i.e call the authenticate function with their username and password).
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Dear Luke,

I am getting shared folder and file inside the folders. But i need to know the users who are having permissions for accessing to a particular file/folder,  I want those members id or email for that particular shared folder. so that i can finish this integration with my web portal. thanks for your help, please let me know as soon as possible.


Please reply.
(Edited)
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
You can get the access controls associated with a folder via the "GET https://account.sf-api.com/sf/v3/Items(id)/AccessControls". That will return each principal (user or group) along with what rights they have on that folder.
Alternatively, you can add the "AccessControls" value to the expand list of an API that returns items to include the access controls of each returned folder item.

You can also get the effective access controls for the current authenticated user on a folder by using the "GET https://account.sf-api.com/sf/v3/Items(id)/Info" api 

You can get more info by expanding the "Api Entities" header on the left side of the API documentation. https://api.sharefile.com/rest/docs/resource.aspx

 
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi 
I have got all user ids by using  get_clients($token); api call. Now i have called 
 https://account.sf-api.com/sf/v3/Items(fo48e5a8-eae1-4da7-b352-10b7ba159c04)/AccessControls

and i got  principal (user or group). but the user id is not matching with principal id.

I
s  it principal id and user  both are same.?

if it is different  then please tell me how can i get user id buy using principal id ?
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
The principal id should be either a user id or group id.
get_clients only gets the client users on your account (not the employee users). Is it possible that they don't have access to the folder? 
Or if they do, it might be because of the group they are in, instead of explicitly by user.

You can get the list of employee users in the account via the 
https://account.sf-api.com/sf/v3/Accounts/Employees API.
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
"The principal id should be either a user id or group id."

if is group id then who can i get the employees in that group. Please give me API.
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
hi Luke,

i am trying to download the file i am getting 200 response but the file is not downloading in to my local.

i have provided my code here please check it once.

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


function download_item($token, $item_id, $local_path) {
    $uri = "https://".get_hostname($token)."/sf/v3/Items(".$item_id.")/Download";
    //echo "GET ".$uri."\n";
     
    $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);
}
 


Please check it once.
(Edited)
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 49 Posts
  • 6 Reply Likes
The Download API (upon success) will return a url you can query to get the actual file content.
So it's a two-step process; first you call Download to get the url, and then you call the url to get the file.
Photo of Vick

Vick

  • 18 Posts
  • 0 Reply Likes
Hi Luke,

          Thanks for your help, i did not understand about this, can you please explain little bit more and help me to download a file in my portal.


Thanks,
Vick.