We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

rk90's avatar
rk90
Helpful | Level 5
7 years ago

list_folder does not return recursive folder listing

API document says: 

recursive Boolean If true, the list folder operation will be applied recursively to all subfolders and the response will contain contents of all subfolders. The default for this field is False.

I am trying to list a folder with recursive=True, but the response does not return the contents of the sub-folders.

Here is the folder structure:

/Team Folder

/Team Folder/file.txt

/Team Folder/sub-folder

/Team Folder/sub-folder/file.txt

 

When I call list_folder on '/Team Folder' with recursive set to True, I do not get the content of 'sub-folder' in response. The response only includes sub-folder not its contents.

 

 

5 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    7 years ago

    Can you share the code and parameter values you're using? That should offer some better context so I can advise on this.

    Feel free to open an API ticket if you'd prefer to share privately. Thanks!

  • rk90's avatar
    rk90
    Helpful | Level 5
    7 years ago

    Here's a sample that may help you understand how I am making the request:

     

    def list_folders(namespace_id):
        url = 'https://api.dropbox.com/2/files/list_folder'
        headers = {"Dropbox-API-Path-Root": json.dumps({".tag": "namespace_id", "namespace_id": namespace_id})
        body = {"path": f"ns:{namespace_id}", "recursive": True, "limit": 2000}
        response = session.post(url, headers=headers, json=body)
        listing = response.json() #And I don't get the recursive listing.  

        

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    7 years ago

    Thanks! That's helpful. There are two things to note here:

    1. Are you getting "has_more": true in the response? If so, you'll need to call back to /2/files/list_folder/continue as covered in the /2/files/list_folder documentation. The nested entries may be on the subsequent pages that would be returned by /2/files/list_folder/continue.
    2. You're specifying "namespace_id" in both the "Dropbox-API-Path-Root" header as well as the "path" value. It may not make a difference for the actual question here, but you only need to include it in one or the other. (If you set the "Dropbox-API-Path-Root" to the namespace ID, you can just use "" as the path.)
  • rk90's avatar
    rk90
    Helpful | Level 5
    7 years ago

    Thanks Greg!

    Yes, 'has_more' is True and when I call `list_folder/continue` with the cursor, I still don't get the recursive folder listing. That is only the child folder is returned in response not its contents. It was working last week.

    As for "Dropbox-API-Path-Root", the only reason I am using is if I don't use it, then some some folder entries appear without path_display field. I understand that field is optional in case the folder is not mounted, but I am listing the team folders' contents as admin so it mount should not even come in picture coz I am not accessing the folder through user's namespace.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    7 years ago

    Thanks for following up. I was able to reproduce the behavior of not seeing the nested entries on the first page, but they are getting returned on the second page for me. (It's worth pointing out though that the exact number of pages is not guaranteed; you always need to check the 'has_more' in the result, even on responses from /2/files/list_folder/continue itself. If you're still getting 'has_more=true', make sure to keep calling back to paginate through all of the results.)

    If this isn't working for you, we'll be happy to investigate, but we'll need some more information. Specifically, it would be helpful to see the actual code/request you're making, including the namespace ID value, and the output you're getting. (Be sure to redact the access token of course, and any other private information.) Please feel free to open an API ticket instead if you prefer to share privately.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 2 days ago
411 Following

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 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!