Take Your Search Game to the Next Level with Dropbox Dash  🚀✨ Curious how it works? Ask us here! 

Forum Discussion

eliotcole's avatar
eliotcole
Explorer | Level 4
5 years ago

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

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

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    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!

    • eliotcole's avatar
      eliotcole
      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

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        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!

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,999 PostsLatest Activity: 55 minutes ago
382 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!