cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Tell us what you want to see on the Community here!
Close

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: 

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

Highlighted

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

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.

15 Replies 15
Highlighted

Re: Get list of files in folders inside shared folders

Dropboxer

To list the contents of a folder nested inside a folder, where you only have the shared link for that top folder, you can use /2/files/list_folder again with the original top-level shared link, but then specify the relative path of the nested folder (e.g. built from the returned 'name' fields), in the "path" parameter.

 

Here's a real example I just ran to illustrate this:

curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer <ACCESS_TOKEN>" \
    --header "Content-Type: application/json" \
    --data "{\"shared_link\": {\"url\": \"https://www.dropbox.com/sh/tpgtd066g1umb13/AACPWhKNrRujRZHM3p7vXP1Qa?dl=0\"}, \"path\": \"\"}"

# {
#   "entries": [
#     {
#       ".tag": "folder",
#       "name": "another folder",
#       "path_lower": "/public/another folder",
#       "path_display": "/Public/another folder",
#       "parent_shared_folder_id": "2448313264",
#       "id": "id:T9-uzcb3s4AAAAAAAAAAFw",
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "2448313264",
#         "traverse_only": false,
#         "no_access": false
#       }
#     },
#     {
#       ".tag": "folder",
#       "name": "some folder",
#       "path_lower": "/public/some folder",
#       "path_display": "/Public/some folder",
#       "parent_shared_folder_id": "2448313264",
#       "id": "id:T9-uzcb3s4AAAAAAAAAAGw",
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "2448313264",
#         "traverse_only": false,
#         "no_access": false
#       }
#     },
#     {
#       ".tag": "folder",
#       "name": "one more folder",
#       "path_lower": "/public/one more folder",
#       "path_display": "/Public/one more folder",
#       "parent_shared_folder_id": "2448313264",
#       "id": "id:T9-uzcb3s4AAAAAAAAAAHA",
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "2448313264",
#         "traverse_only": false,
#         "no_access": false
#       }
#     },
#     {
#       ".tag": "file",
#       "name": "Getting Started.pdf",
#       "path_lower": "/public/getting started.pdf",
#       "path_display": "/Public/Getting Started.pdf",
#       "parent_shared_folder_id": "2448313264",
#       "id": "id:25N5ksooX-sAAAAAAAKbwQ",
#       "client_modified": "2015-01-30T22:53:09Z",
#       "server_modified": "2018-02-16T18:05:53Z",
#       "rev": "191ee4bb0",
#       "size": 249159,
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "2448313264",
#         "modified_by": "dbid:AABL4QRrY7tB9viLgPUqmjkzE6Fe5ujlnlE"
#       },
#       "is_downloadable": true,
#       "content_hash": "c3dfdd86981548e48bc8efb6c4162c76ba961ec92e60f6ba26189068a41fcaf2"
#     },
#     {
#       ".tag": "file",
#       "name": "hello.txt",
#       "path_lower": "/public/hello.txt",
#       "path_display": "/Public/hello.txt",
#       "parent_shared_folder_id": "2448313264",
#       "id": "id:25N5ksooX-sAAAAAAAAZYA",
#       "client_modified": "2014-07-02T01:28:43Z",
#       "server_modified": "2018-02-16T18:05:53Z",
#       "rev": "291ee4bb0",
#       "size": 14,
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "2448313264",
#         "modified_by": "dbid:AABL4QRrY7tB9viLgPUqmjkzE6Fe5ujlnlE"
#       },
#       "is_downloadable": true,
#       "content_hash": "82674cafa4320daa280b666af141db2b5bd7db4dff3b69dd91a6caea9e30dafb"
#     }
#   ],
#   "cursor": "AAE77A9T4tcyL7eoj_qL_4C735arjRfDRL8yg-yBRm0LxVYkGlPWtyoihPXig3uKLM8EUBmtUHXDMMnqSzkkbCAeqy3e3IeX2M1rV2NtNKobfmPVVMbK1LiOyn9jI9AsDnF8HHkbgGnlgUw4CvJ1Y1q2pJU-UMzy7qR6K8nYhe2vAcuTfBJmSFgCny3YXlutGJZFubiv9n0-Xmr-i7f5ctcSDUqfw1_sw4mGGmHGIyo3lP_1XJRD9DOOW7WZTYt2Uwr3sVjluPJmO93MUMlu6zEs3pB7xVVTNKk4J24IdcSH2A",
#   "has_more": false
# }


curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer <ACCESS_TOKEN>" \
    --header "Content-Type: application/json" \
    --data "{\"shared_link\": {\"url\": \"https://www.dropbox.com/sh/tpgtd066g1umb13/AACPWhKNrRujRZHM3p7vXP1Qa?dl=0\"}, \"path\": \"/another folder\"}"

# {
#   "entries": [
#     {
#       ".tag": "file",
#       "name": "test.png",
#       "path_lower": "/public/another folder/test.png",
#       "path_display": "/Public/another folder/test.png",
#       "parent_shared_folder_id": "2448313264",
#       "id": "id:T9-uzcb3s4AAAAAAAAAAIA",
#       "client_modified": "2020-06-23T15:46:34Z",
#       "server_modified": "2020-06-23T15:46:35Z",
#       "rev": "5a8c2439cb67d91ee4bb0",
#       "size": 1427,
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "2448313264",
#         "modified_by": "dbid:AABL4QRrY7tB9viLgPUqmjkzE6Fe5ujlnlE"
#       },
#       "is_downloadable": true,
#       "content_hash": "3c6f88e464f1389ab9fc1a0c28c335e357bc61cf76e10e7bf3f146795e64e9f7"
#     }
#   ],
#   "cursor": "AAFWX5jkg5A6CEUiSOA_lCsuVVHlv2yCFtEkrE9CE4gKFmM3XFjUKL2znkL8V9104ofmyRBuSTIcjl1OOMy6_iuI21csGMIwqapxis_E0azOD7ZMDJQ0tJjMJ39sZ9i-WitNwuu0TDgzJn0UjDr7b9ZFktktVvK9VM5zB3W-3as0YaLmPpb8-4MovsdSiaQ12CSBRClnNVXSOa1T6SSOy3ktqn3SxFyr_fbXlzoevO2RiKthJHgdcFg7BGe89LN4_UKvpPFVGLZFdk6ZX6txXe3fW4Nuvq6k8a0HjLYSJt_yz_417KcLw8-a9sa97OxUYHXjqiDfkKWztFzEX4mWGpky",
#   "has_more": false
# }

Hope this helps, or let me know if I've misunderstood your use case!

Highlighted

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

Explorer | Level 4

Hi, Greg, thanks for that, but as stated, it doesn't work, because the URL for the subfolder is not the same as that of the main folder.

 

I'll try again, though.

 

Thanks for splitting this out, though. Since it has been split, then, could we change the title, perhaps, please? (I'll try, too)

 

Perhaps:

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

Highlighted

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

Dropboxer

Thanks for following up. I see you did successfully rename the thread.

 

Anyway, I understand that the shared link, e.g., as seen in the browser, is not the same for the subfolder as the main folder, but to call /2/files/list_folder for a subfolder, you don't actually need the shared link for the subfolder in particular. You just need the combination of the shared link for the main folder, and the relative path of the subfolder.

 

Check out the two API calls in the sample I posted. The first lists the contents of the main folder using its shared link, and the second list contents of a subfolder using that same main folder shared link, plus the relative path, constructed from the information in the first response.

 

If I understand correctly, that satisfies your use case here, but please elaborate if not. Thanks!

Highlighted

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

Explorer | Level 4

Hi, @Greg-DB , cheers ... I mean ... it sounds like it should ... but now I'm just hit with more issues.

 

I'm starting from scratch, and when I run the code that you gave with the URL I now get this error:

Error in call to API function "files/list_folder": request body: shared_link: unknown field 'path'
Highlighted

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

Dropboxer

It sounds like you accidentally moved a "}" when copying in your shared link. The "path" parameter should be a top-level parameter, not part of the "shared_link" parameter object.

Highlighted

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

Explorer | Level 4

You're quite right, cheers muchly, mate! :ThumbsUpAll: !! That managed to list the folder. Although, I don't think I would've *ever* worked that out from the documentation. :weary:

 

However all that said, I'm still not seeing any URL that I can use externally in any of those details, since experience has shown that the link plus the folder will not be a link that works in a browser.

 

Should I parse the parent_shared_folder_id in a file that's contained in the subfolder to then perform a folder metadata call with it to get the url?

 
I feel like that's going to be problematic if the folder is empty, though. Additionally, it would seem like a bit of a round the houses way to get links to subfolders.
 

@Greg-DB wrote:

It sounds like you accidentally moved a "}" when copying in your shared link. The "path" parameter should be a top-level parameter, not part of the "shared_link" parameter object.



Highlighted

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

Dropboxer

The /2/files/list_folder response doesn't include shared links for entries, nested or not. It does include the normal File/FolderMetadata for the entries though, so you can use that metadata in your app. To step back a bit though, what functionality are you trying to build?

 

For example, if you then want to programamtically download a file from one of the subfolders, you can then use /2/sharing/get_shared_link_file with the original main shared link and relevant relative path again to do so.

 

Alternatively, if you do just want the nested shared link itself, e.g., to hand off to the user to display in the browser, that isn't available on the API. Let me know if that's the end goal and I'll pass it along as a feature request though.

Highlighted

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

Explorer | Level 4

Hi, Greg

 

Thanks again!

 

Basically, yeah, that's the goal, so it'd be awesome if you could pass that on as a feature request.

 

I will accept the latest answer as a solution, but I think it's an amalgam of them all.

 

I think one of the issues with my previous code was that I was *completely* unaware of the "shared_link" part, which didn't seem to jump out at me whilst perusing the docs, but maybe I'm blind! 

 

Would it be possible to use some combination of any of this with any of the online automation tools, such as Microsoft's powerful Power Automate stuff? Or maybe automate.io's much improving interface?

 

Oh, and in a while I'll come back and edit this post with some view on what I've put together so it's cogent.

E


@Greg-DB wrote:

The /2/files/list_folder response doesn't include shared links for entries, nested or not. It does include the normal File/FolderMetadata for the entries though, so you can use that metadata in your app. To step back a bit though, what functionality are you trying to build?

 

For example, if you then want to programamtically download a file from one of the subfolders, you can then use /2/sharing/get_shared_link_file with the original main shared link and relevant relative path again to do so.

 

Alternatively, if you do just want the nested shared link itself, e.g., to hand off to the user to display in the browser, that isn't available on the API. Let me know if that's the end goal and I'll pass it along as a feature request though.


 

Highlighted

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

Dropboxer

Got it, thanks! I'll send this along to the team. (I can't promise if/when it might be implemented though.)

 

I can't speak to those third party automation tools though, as they're not made by Dropbox.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?