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: Programmatically Process Shared Link Folders and Sub-Folders and Their Contents

Programmatically Process Shared Link Folders and Sub-Folders and Their Contents

eliotcole
Explorer | Level 4

Well I'm still at a loss.

 

I have the shared link to a folder that I need to check on a daily schedule to see if there's new files. The logic of which is all fine, but I just can't access anything below the initial shared link programatically.

 

Really all I need to get is the URL for any subfolder ... but I'll be damned if there's an API call that will supply that information.

 

  1. I have tried with the API token provided by the DB Dev Docs (auto).
  2. I have tried with my own token in place of that (to make the API call come from my account).
  3. I have tried all of the following and none can penetrate the barrier that is the second level of folders:
    1. get_shared_link_metadata
    2. get_folder_metadata
    3. list_received_files
    4. list_folder
    5. list_folders

 

I have access to the shared link, I have access to all the (3) subfolders.

 

One thing I note is that the URL changes once I enter the subfolder of the main shared link, and I'm unable to programattically

get that to just launch either a new get_shared_link_metadata on the new URL, or list_folder to get its contents. So if we had a primary shared link of:

https://www.dropbox.com/sh/aaa/bbb/

Let's say that has a subfolder called "john", I can't resolve that via the API because the URL to the john folder is not:

https://www.dropbox.com/sh/aaa/bbb/john

The link, instead, is:

https://www.dropbox.com/sh/aaa/ccc/john

 

A quick breakdown of how I would desire this to work:

Stage 1:

get_shared_link_metadata ---> list_folder

This works, and provides me with the contents of the shared folder, and the names and IDs of the subfolders.

Stage 2:

UNKNOWN ---> list_folder

This is the repeated stage (for each of the 3 subfolders), the UNKNOWN represents what I don't know, that should essentially be the equivalent of the get_shared_link_metadata ... except I don't have the right link for the subfolders, because they are changed each time.

16 Replies 16

eliotcole
Explorer | Level 4

Ello, I'm back again! 🙂

 

I'm still trying to make this work.

 

I'm working with the copy, now.

 

So, let's say that I have this shared folder:

 

https://www.dropbox.com/sh/g0ja3gk1u1pjf9y/AADjilHpLqi-e5PO-RGp4PHIa?dl=0

 

That shared folder has a subfolder called:

 

test5

If I would like to copy the contents of that test5 subfolder to a given folder in the API, what am I putting in the 'from_path' field in this JSON?

 

 

{
    "from_path": "WHATGOESHERE?",
    "to_path": "/destination5",
    "allow_shared_folder": true,
    "autorename": false,
    "allow_ownership_transfer": false
}

 

 

 

 

------

 

 

Here's a few attempts that I've made that have failed miserably:

Spoiler

1.

{
    "from_path": "https://www.dropbox.com/sh/g0ja3gk1u1pjf9y/AADjilHpLqi-e5PO-RGp4PHIa/test5",
    "to_path": "/destination5",
    "allow_shared_folder": true,
    "autorename": false,
    "allow_ownership_transfer": false
}

2.

 

{
    "shared_link": { "url": "https://www.dropbox.com/sh/g0ja3gk1u1pjf9y/AADjilHpLqi-e5PO-RGp4PHIa" },
    "from_path": "/test5",
    "to_path": "/destination5",
    "allow_shared_folder": true,
    "autorename": false,
    "allow_ownership_transfer": false
}

3.

 

 

{
  "from_path": {
    "shared_link": {
      "url": "https://www.dropbox.com/sh/g0ja3gk1u1pjf9y/AADjilHpLqi-e5PO-RGp4PHIa"
    },
    "path": "/test5"
  },
  "to_path": "/destination5",
  "allow_shared_folder": true,
  "autorename": false,
  "allow_ownership_transfer": false
}

 

I've also tried to have a look at the JAVA SDK builder, as I think that you actually recommended that someone was able to do it with that ... but I really don't understand how to use that.

Greg-DB
Dropbox Staff

Unfortunately, the Dropbox API doesn't offer a way to copy from a shared link into the connected Dropbox account via the API like this, but I'll pass this along as a feature request as well. I can't promise if/when that might be implemented though. 

 

The /2/files/copy_v2 call (or native method in an SDK) that you're referring to only supports copying files from one location in the connected account to another location in the same account. It doesn't support using a shared link as the source. 

 

You could download the files, using /2/sharing/get_shared_link_file, and then upload them to the account, e.g., using /2/files/upload, but that would be comparatively inefficient of course.

eliotcole
Explorer | Level 4

Cheers, Greg, and thanks for taking it to the developers.

 

I will say that I've perused a few topics on this, and they've all been at least a year old, so I'm wondering if there's ever actually going to be any real movement with the (Public) Shared Folders/Links. (i'm not saying that in a tone that would indicate an attack on your person, mate ... just ... it seems like it's something that isn't desired for the public to have)

 

I guess, then, my final question would be what API command would you see as the best use case with regards to a cloud based implementation that may have size limits (let's take the Google API with limits size to 50MB per upload/download).

 

 

I would imagine that a "download then upload" won't be the ideal solution for that, would it? Would something like " get_temporary_link " work better. So it would:

  1. Locate a file ID.
  2. Generate a temporary link.

Allow that link to be used to directly access the file in question?

 

To be clear, I'm not stating that in a literal fashion, just using the get_temporary_link as an example, I'm sure there's a more appropriate function to achieve this.

 

Essentially, once I have identified a file that I would like to copy to another (let's assume an external API to work this out better) then I need to essentially be given a direct link to the file, somehow, to present to the other API. How would I get that link?

 

 

----

Would it perhaps be " get_shared_link_file " ?

 

If so, how would that work with the previously mentioned subfolder issues in that path?

 

 

https://content.dropboxapi.com/2/sharing/get_shared_link_file

 

 

 

(I'm about to attempt it, but will try to play it out here, too)

Greg-DB
Dropbox Staff

Right, whenever possible, it's best to avoid unnecessarily uploading/downloading locally, for the sake of reliability and efficiency. Passing a link between two services, if supported, would likely be faster.

 

In this case, if you need a direct link to a file hosted on Dropbox, the specifics will depend on if the file exists in the Dropbox account you're connected to via the API (i.e., the one for which you have an access token).

 

If the file is in the connected account, /2/files/get_temporary_link would be a good option. That gives you a direct link to the file content, that you could hand off to the other service. Note that these links only last for four hours.

 

If the file is not in the connected account though, and say, you just have a shared link, /2/files/get_temporary_link won't work. Instead, this will depend on the shared link you have. If the shared link is already for the file itself, you can modify it for direct access as covered here. However, if the shared link is just for a parent folder, as discussed through this thread, then unfortunately there isn't a good solution. As earlier, the API doesn't offer a way to get a link to just the nested file based on a shared link to the folder that contains it.

eliotcole
Explorer | Level 4

Thanks again for coming back on this, mate. Really very much appreciated.

 

One last question ... how about the whole folder? That is, we know, not nested, and available at root.

 

Is there any internal reason given as to why the access to Shared Files is so antiquated (sorry) ... or ... let's be honest ... restrictive ... next to the rest of the interface? It seems ... odd. Particularly given the removal of RSS and the way that people use Shared Folders.

 

----

Also, not for nothing, but then this particular guide should include that Shared Sub-Folders are essentially not accessible via the API:

DBX File Access Guide - Dropbox (the "Non-downloadable files" section)

 

Greg-DB
Dropbox Staff

Thanks for the feedback! I can't speak to why any particular feature was or wasn't implemented, but we appreciate you taking the time to share this. I'll send it along.

 

 

If you have a shared link for a folder and wish to get a direct link to that, you can likewise modify that as documented here. For folders, that will give you a .zip file of the folder.

Greg-DB
Dropbox Staff

Update: The Dropbox API now returns the shared link for the nested item as 'url' when requesting the metadata for that item using the "path" parameter on /2/sharing/get_shared_link_metadata (instead of the original parent link).

Need more support?