cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Unable to fecth files and folders from Team folders

Unable to fecth files and folders from Team folders

Kuki
Explorer | Level 4
Go to solution

I am using the Dropbox Business API and trying to fetch Folders and Files present into my team folder (If you will see I have created a "General Information" folder) (The folder which is out side of Member folders purpple color)
but I am not able to fetch anything using this API..

Although I can fetch all the files and folders present into Purpple color Folder(team member and Admin) but the folder which is outside of member folder creating issue.
I read your documentation and seacrhed lot of things but not find any solution.
Some where it is written that using namespaces it is possible, I tried with it as well but unsuccesfful.
Could ypu please tell me the exact code how to do it

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

The exact number of entries you get back per /2/files/list_folder[/continue] page is not guaranteed. Sometimes the API may return more entries per page, and sometimes it may return fewer.

Regardless of how many entries were returned, your app needs to always check the 'has_more' value and call back for more entries if it's 'true'.

View solution in original post

10 Replies 10

Greg-DB
Dropbox Staff
Go to solution

By default, API calls will operate inside your "member folder" (the purple folder), but you can configure them to operate in the "team space" (above the member folder) if you want. To do so, you need to set the 'Dropbox-API-Path-Root' header. You can find information on how to use that in the Namespace Guide here:

https://www.dropbox.com/developers/reference/namespace-guide

If something isn't working as expected, please share the code and unexpected output (but redact your access token).

Kuki
Explorer | Level 4
Go to solution

Thank You for your reply: Please see my code and process I followed below:

1. STEP1: First I tried to find the the namespace ID's of the folder I have creared. I got the following output when I executed the API:

https://api.dropboxapi.com/2/team/namespaces/list

[namespaces] => Array
(
[0] => Array
(
[name] => Your team's shared workspace
[namespace_id] => 6131728736
[namespace_type] => Array
(
[.tag] => team_folder
)

)

[1] => Array
(
[name] => Sales
[namespace_id] => 6131729056
[namespace_type] => Array
(
[.tag] => shared_folder
)

)
[2] => Array
(
[name] => Custom_team_folder
[namespace_id] => 6512687312
[namespace_type] => Array
(
[.tag] => shared_folder
)

)

-----------------------------------------------------------------------------------------------

2. STEP2: Then I call this API https://api.dropboxapi.com/2/files/list_folder and passed the Namespace Id "6512687312" into my code, to get the list of files and folder present into the "Custom_team_folder" .
But I got this error:
"Operation completed without any errorsError in call to API function "files/list_folder":
This API function operates on a single Dropbox account, but the OAuth 2 access token you provided is for an entire Dropbox Business team. Since your API app key has team member file access permissions, you can operate on a team member's Dropbox by providing the "Dropbox-API-Select-User" HTTP header or "select_user" URL parameter to specify the exact user."

Could I know How can I solve this error, why I am getting this error

This is My code: I used CURL using PHP:

<?php

$data = array("path"=>'');
$payload = json_encode($data);

$ch = curl_init('https://api.dropboxapi.com/2/files/list_folder');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$payload);

$headers = array(
'Content-type: application/json',
'Dropbox-API-Path-Root: {".tag": "namespace_id", "namespace_id": "6512687312"}',
'Authorization: Bearer <REDACTED>',
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
$result_file_names = curl_exec($ch);
echo 'Operation completed without any errors';
}
print_r($result_file_names);


curl_close($ch);


exit;

?>

Please see the screen shot for more reference:

----------------------------------------------------------------------------------------------------

 

I hope I will get the solution now.

Greg-DB
Dropbox Staff
Go to solution

Thanks for the additional information. Please note that you should never share your access token like this. I've redacted it from your post, but you should revoke the token since you shared it publicly.

Anyway, you're getting this error because you're using an access token for an entire Business team to call a user-specific endpoint. You can do so, but you'll need to specify which team member to operate on. You can find information on how to do so under the "Member file access" section here:

https://www.dropbox.com/developers/documentation/http/teams#teams-member-file-access

Kuki
Explorer | Level 4
Go to solution

Sure, I will rember it..

Now lets come to query:  with reference to what you suggested above, the folder "Custom_team_folder" is not inside any team member , it is outside of all team member folder, Please see the attached Image.. So How can I specify which team member this folder present in.AAA.png

Greg-DB
Dropbox Staff
Go to solution

Your screenshot is showing your "team space", so to access it via the API you should set the 'Dropbox-API-Path-Root' header accordingly.

For example, to set the root to your team space itself, under which you can access the "Custom_team_folder" folder, you would set the root and path like this:

curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer <ACCESS_TOKEN>" \
    --header "Dropbox-API-Select-User: <MEMBER_ID>" \
    --header "Content-Type: application/json" \
    --header 'Dropbox-API-Path-Root: {".tag": "root", "root": "6131728736"}' \
    --data "{\"path\": \"/Custom_team_folder\"}"

Or, to set the root to the "Custom_team_folder" shared folder namespace directly, you could call like this:

curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer <ACCESS_TOKEN>" \
    --header "Dropbox-API-Select-User: <MEMBER_ID>" \
    --header "Content-Type: application/json" \
    --header 'Dropbox-API-Path-Root: {".tag": "namespace_id", "namespace_id": "6512687312"}' \
    --data "{\"path\": \"\"}"

I recommend reviewing the Namespace Guide as it goes over these options in more detail.

Kuki
Explorer | Level 4
Go to solution

Hello Again,

I tried the solution you suggested , but it is not working fully.

 

[3] => Array
(
[.tag] => folder
[name] => General Information
[path_lower] => /general information
[path_display] => /General Information
[parent_shared_folder_id] => 6131728736
[id] => id:z3mu7FjeX1AAAAAAAAAAAQ
[shared_folder_id] => 6498180480
[sharing_info] => Array
(
[read_only] =>
[parent_shared_folder_id] => 6131728736
[shared_folder_id] => 6498180480
[traverse_only] =>
[no_access] =>
)

)
There is some issue,
I have created a "General Information" (6498180480 ) folder at team space,
Then I created a Folder "New_folder_123" inside it, and I shared this folder to one of my member.
I uploaded some file inside this folder, But when I am trying to retrive the files i uploaded into shared folder, showing nothing, While the files which is inside of ("Romi") folder parallel to the shared folder is coming into the list
Could you suggest me the reason

<?php


$data = array("path"=>"", "recursive"=> true);
$payload = json_encode($data);

$ch = curl_init('https://api.dropboxapi.com/2/files/list_folder');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$payload);

$headers = array(
'Dropbox-API-Select-User:<MEMBER_ID>',
'Content-type: application/json',
'Dropbox-API-Path-Root: {".tag": "namespace_id", "namespace_id": "6498180480"}',
'Authorization: Bearer <REDACTED>',
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
$result_file_names = curl_exec($ch);
echo 'Operation completed without any errors';
}
$array_result_file_names= json_decode($result_file_names,true);
print_r($array_result_file_names);


curl_close($ch);


exit;

?>

Greg-DB
Dropbox Staff
Go to solution

In the /2/files/list_folder response, what is the value of 'has_more'? If it's 'true', you need to call back to /2/files/list_folder/continue to retrieve more entries.

A single call to /2/files/list_folder isn't guaranteed to return all of the results. You should always have your app check this value and call back as necessary. You can find more information in the documentation

Kuki
Explorer | Level 4
Go to solution

Hello Again,

A bit  More:

Everything is working fine now, I am able to acess everything now,

The problem is :  Records (Number of Folders and Files vary when I call the API).

When I call the API ( /2/files/list_folder and  /2/files/list_folder/continue ) first time it shows exact no of files , but when I call it again it chages the no of files and folders, but when again I call the same, it shows exact no of records.

Means, to get exact no of Files , I will have to call then API around 3 to 4 times.

Actually , I called the API's at page load, when first time page loads it shows the records properly, when I again refresh/load  the page records count not comes properm , when I load/refresh the page again, not comes the recods properly.

Somtime to get the exact no of records , I have to refesh tha page 4 to 5 times

Could you please tell me the reason behind it.

Greg-DB
Dropbox Staff
Go to solution

The exact number of entries you get back per /2/files/list_folder[/continue] page is not guaranteed. Sometimes the API may return more entries per page, and sometimes it may return fewer.

Regardless of how many entries were returned, your app needs to always check the 'has_more' value and call back for more entries if it's 'true'.

Need more support?