Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
eliotcole
6 years agoExplorer | Level 4
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 anythi...
Greg-DB
Dropbox Community Moderator
6 years agoTo 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!
- eliotcole6 years agoExplorer | 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-DB6 years ago
Dropbox Community Moderator
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!
- eliotcole6 years agoExplorer | 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'
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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, Facebook or Instagram.
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!