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: Get contents of a shared folder

Get contents of a shared folder

HE A.
New member | Level 2

I have a web app built in PHP, so I'm using v1 of the Dropbox API. When I request the metadata for a folder, it only returns a list of entries (files in the folder) if the folder is not shared. How would I get the contents for a shared folder?

Also, is there a way to use the "move" call to move all files in a folder? I tried wildcard pathnames, but they were rejected. My goal is move all files without moving the folder itself. If I can't get the filenames for a shared folder, then I'm hoping I can just move all of the files at once, so I don't have to iterate through the list of filenames.

Thanks.

5 Replies 5

Greg-DB
Dropbox Staff

You should certainly be able to list the contents of a shared folder using the API just like you would a non-shared folder. I just tried it out and it's working for me. Can you share some sample code and output showing the issue you're seeing?

If you're using getDelta, make sure you check the returned "has_more" value and call back if it's true.

Also, it's not currently possible to move all of the contents of a folder, but not the folder itself, in one API call, but I'll be sure to pass this along as a feature request. 

HE A.
New member | Level 2

Thanks for the help. I included the code for the call and the resulting response below. The "subfolder" contains a file, but that file doesn't appear in the entries. When I make the same call to the "superfolder", it does include any files in the folder. 

I thought the difference was that the subfolder is shared, but maybe it's related to something else? 

Also, the "has_more" value is true, but I'm not sure how to call back again -- do I change one of the parameters or just make the same call right away?

Last note -- I'm setting the cursor to null, because I'm not yet tracking the cursor. 

CALL
$cursor = null;
$pathPrefix = '/superfoldername/somesubfoldername';
$result = Dropbox::getDelta($cursor, $pathPrefix);

RESULT
array(4) {
["has_more"]=> bool(true)
["cursor"]=> string(302) "somecursorstring"
["entries"]=> array(1) {
[0]=> array(2) {
[0]=> string(49) "/superfoldername/somesubfoldername"
[1]=> array(13) {
["rev"]=> string(10) "2047cde5ef"
["thumb_exists"]=> bool(false)
["path"]=> string(49) "/superfoldername/somesubfoldername"
["is_dir"]=> bool(true)
["icon"]=> string(11) "folder_user"
["read_only"]=> bool(false)
["modifier"]=> NULL
["bytes"]=> int(0)
["modified"]=> string(31) "Sun, 01 May 2016 16:38:32 +0000"
["shared_folder"]=> array(2) {
["shared_folder_id"]=> string(10) "1205541233"
["is_team_only_shared_folder"]=> bool(false) }
["size"]=> string(7) "0 bytes"
["root"]=> string(7) "dropbox"
["revision"]=> int(32)
}
}
}
["reset"]=> bool(true)
}

Greg-DB
Dropbox Staff

Thanks! Since has_more is true, you should immediately call getDelta again, with $cursor set to the "cursor" value returned from the previous call. (The HTTP documentation for /delta contains some additional information on using it.)

HE A.
New member | Level 2

Thanks, that worked! 

I didn't expect the results to come back in chunks, because the total size was relatively small. Do you know if the chunking is based on size, or does it chunk based on some logic? If logic, do you know what the logic is (e.g., every folder is a separate chunk)? I'm just trying to reduce the number of calls that we make.

One last question -- after I make a call to move the files out of a folder, will the API then trigger a webhook saying that the state has changed? I'm guessing that the answer is yes. If so, my process seems to cause a lot of back-and-forth, something like this:

- User drops a file in the folder.

- My app receives a webhook saying that the folder has changed.

- Send a delta request to the Dropbox API (send multiple times to get the full details).

- Send a move request to the Dropbox API to move the file from the source folder to a destination folder in the same account.

- My app receives two webhooks saying that the source folder and the destination folders have changed.

- Send a delta request for each webhook, including multiple calls to get the full details. 

- Determine that nothing has changed, so ignore these last two webhooks.

Is there some way to shorten this process, especially the last two webhooks? Is it possible to ignore the final webhooks using cursors or some other strategy?

Thanks!

Greg-DB
Dropbox Staff

I believe there are a few different factors that determine the paging, so you should just make sure your app always checks and follows the has_more and reset indicators to make sure it's always working from correct data.

And yes, Dropbox will send webhook notifications for any changes in the linked accounts. Your process sounds right for the most part, but be careful managing concurrency when you receive multiple notifications for the same user. There's a note about this at the bottom of the documentation here:

https://www.dropbox.com/developers/reference/webhooks

You may also want to "debounce" the calls you make in response to webhook notifications. I.e., wait a certain amount of time after receiving a webhook notification for a user before making the delta call, in case there are more webhook notifications coming in anyway.

Need more support?