<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Listing every team folder and date last modified in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Listing-every-team-folder-and-date-last-modified/m-p/680204#M30657</link>
    <description>&lt;P&gt;I am trying to list every dropbox team folder and a date against it that specifies the last time a file within was modified.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been successful in listing folders with the below script however, the problem is that the folders being listed are only what the "as_admin" account has access to. Is there a way using the admin account to list everything regardless of folder access? I have full control of the api scope so if there is something there, I can easily change it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def establish_connection():
    # Create an instance of the Dropbox API client
    try:      

        dbx_team = dropbox.DropboxTeam(os.environ['ACCESS_TOKEN'])
        # get the team member id for common user
        members = dbx_team.team_members_list()

        dbx_team = dropbox.DropboxTeam(os.environ['ACCESS_TOKEN']).as_admin("")

    except AuthError as e:
        print(f"Error connecting to Dropbox API: {e}")
        exit()
    return dbx_team


def list_team_folders():
    
    dbx_team = establish_connection()

    
    folders = []
    result = dbx_team.files_list_folder(path='')
    while True:
        for entry in result.entries:
            if isinstance(entry, dropbox.files.FolderMetadata):
                folders.append(entry.path_display)
        if not result.has_more:
            break
        result = dbx_team.files_list_folder_continue(result.cursor)

    # Iterate over each folder and get the latest modified date of its files
    for folder in folders:
        latest_modified = datetime(1970, 1, 1) # Set to an arbitrary old date
        result = dbx_team.files_list_folder(path=folder)
        while True:
            for entry in result.entries:
                if isinstance(entry, dropbox.files.FileMetadata):
                    # Check if this file was modified more recently than the current latest modified date
                    modified = datetime.strptime(str(entry.client_modified), '%Y-%m-%d %H:%M:%S')
                    if modified &amp;gt; latest_modified:
                        latest_modified = modified
            if not result.has_more:
                break
            result = dbx_team.files_list_folder_continue(result.cursor)
        print(f'{folder}: {latest_modified}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Apr 2023 11:57:42 GMT</pubDate>
    <dc:creator>mja101</dc:creator>
    <dc:date>2023-04-27T11:57:42Z</dc:date>
    <item>
      <title>Listing every team folder and date last modified</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Listing-every-team-folder-and-date-last-modified/m-p/680204#M30657</link>
      <description>&lt;P&gt;I am trying to list every dropbox team folder and a date against it that specifies the last time a file within was modified.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been successful in listing folders with the below script however, the problem is that the folders being listed are only what the "as_admin" account has access to. Is there a way using the admin account to list everything regardless of folder access? I have full control of the api scope so if there is something there, I can easily change it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def establish_connection():
    # Create an instance of the Dropbox API client
    try:      

        dbx_team = dropbox.DropboxTeam(os.environ['ACCESS_TOKEN'])
        # get the team member id for common user
        members = dbx_team.team_members_list()

        dbx_team = dropbox.DropboxTeam(os.environ['ACCESS_TOKEN']).as_admin("")

    except AuthError as e:
        print(f"Error connecting to Dropbox API: {e}")
        exit()
    return dbx_team


def list_team_folders():
    
    dbx_team = establish_connection()

    
    folders = []
    result = dbx_team.files_list_folder(path='')
    while True:
        for entry in result.entries:
            if isinstance(entry, dropbox.files.FolderMetadata):
                folders.append(entry.path_display)
        if not result.has_more:
            break
        result = dbx_team.files_list_folder_continue(result.cursor)

    # Iterate over each folder and get the latest modified date of its files
    for folder in folders:
        latest_modified = datetime(1970, 1, 1) # Set to an arbitrary old date
        result = dbx_team.files_list_folder(path=folder)
        while True:
            for entry in result.entries:
                if isinstance(entry, dropbox.files.FileMetadata):
                    # Check if this file was modified more recently than the current latest modified date
                    modified = datetime.strptime(str(entry.client_modified), '%Y-%m-%d %H:%M:%S')
                    if modified &amp;gt; latest_modified:
                        latest_modified = modified
            if not result.has_more:
                break
            result = dbx_team.files_list_folder_continue(result.cursor)
        print(f'{folder}: {latest_modified}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 11:57:42 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Listing-every-team-folder-and-date-last-modified/m-p/680204#M30657</guid>
      <dc:creator>mja101</dc:creator>
      <dc:date>2023-04-27T11:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Listing every team folder and date last modified</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Listing-every-team-folder-and-date-last-modified/m-p/680287#M30665</link>
      <description>&lt;P&gt;As you found, starting from files_list_folder(path='') will only list the contents of that particular member's folder; if there are other team folders that the member doesn't have mounted in their account, those team folders won't be found that way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can list all team folders for a team using &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.DropboxTeam.team_team_folder_list" target="_blank"&gt;team_team_folder_list&lt;/A&gt;/&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.DropboxTeam.team_team_folder_list_continue" target="_blank"&gt;team_team_folder_list_continue&lt;/A&gt; though. (Similarly, if you want to list all "namespaces", which includes team folders, you can use &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.DropboxTeam.team_namespaces_list" target="_blank"&gt;team_namespaces_list&lt;/A&gt;/&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox_client.DropboxTeam.team_namespaces_list_continue" target="_blank"&gt;team_namespaces_list_continue&lt;/A&gt;.) These methods are called using a DropboxTeam instance, not a Dropbox instance, so you would call them without the 'as_admin'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, you can start listing any arbitrary team folder like this:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;dbx_team.as_admin(admin_id).files_list_folder("ns:" + team_folder_id)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for reference, if you need to list a "team space", refer to &lt;A href="https://developers.dropbox.com/dbx-team-files-guide" target="_blank"&gt;the Team Files Guide&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 17:44:52 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Listing-every-team-folder-and-date-last-modified/m-p/680287#M30665</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-04-27T17:44:52Z</dc:date>
    </item>
  </channel>
</rss>

