You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

adsalguero's avatar
adsalguero
Explorer | Level 4
30 days ago

GET Usage (in MB, updates every 8 hours) FROM python sdk

Hello, 

 

I want to obtain the corresponding values for Usage (in MB, updates every 8 hours) obteined using the manual export member data in the admin console. 

 

Currently this is my test code: 

def get_users_list(token) :
    dbx = dropbox.DropboxTeam(token)
    members = dbx.team_members_list(include_removed= True).members

    # Collect member information
    member_data = []
    for member in members:
        member_info = {
            "team_member_id": member.profile.team_member_id,
            "email": member.profile.email,
            "status": str(member.profile.status),
            "role": str(member.role)
        }
        member_data.append(member_info)

    # Get the path to the parent directory of the current script's directory
    parent_dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

    # Write user data to a JSON file in the parent directory
    json_file_path = os.path.join(parent_dir_path, 'get_users_list.json')
    with open(json_file_path, 'w') as json_file:
        json.dump(member_data, json_file, indent=4)
   
    print(f"List members data has been written to '{json_file_path}'")
    return member_data 

 

def get_team_members(dbx_team) : 
    members = []
    result = dbx_team.team_members_list()
    members.extend(result.members)
    while result.has_more:
        result = dbx_team.team_members_list_continue(result.cursor)
        members.extend(result.members)
    return members

if __name__ == "__main__":

    if access_token:

        dbx_team = dropbox.DropboxTeam(access_token)
        data = get_users_list(access_token)
       
        specific_member = {
                "team_member_id": "xxxxxx",
                "email": "xxxxx",
                "status": "xxxxx",
                "role": "Axxxx"
        }

        # Procesar solo el miembro específico
        user_dbx = dbx_team.as_user(specific_member['team_member_id'])
        account_info = user_dbx.users_get_space_usage()
        used_bytes = account_info.used
        allocation = account_info.allocation

        if allocation.is_individual():
            total_bytes = allocation.get_individual().allocated
        elif allocation.is_team():
            total_bytes = allocation.get_team().allocated
        else:
            total_bytes = 'Desconocido'

        used_mb = used_bytes / (1024 ** 2)  # Convertir a MB
        total_mb = total_bytes / (1024 ** 2) if total_bytes != 'Desconocido' else 'Desconocido'

        print(f"Usuario: {specific_member['email']}")
        print(f"Espacio utilizado (bytes): {used_bytes}")
        print(f"Espacio total (bytes): {total_bytes}")
        print(f"Espacio utilizado (MB): {used_mb:.2f}")
        print(f"Espacio total (MB): {total_mb}\n")

        # Obtener el espacio utilizado y total para el miembro específico usando dbx
        account_info = user_dbx.users_get_space_usage()
        used = account_info.used
       
        print(f"Espacio utilizado: {used/ (1024 ** 2)} megabytes")
 
 
But I only get "Data (MB) member has access to".


this is my test response 

Usuario: xxxxxxx

Espacio utilizado (bytes): 12290447226920
Espacio total (bytes): 11922399716966400
Espacio utilizado (MB): 11721083.86
Espacio total (MB): 11370086400.0

Espacio utilizado: 11721083.85 megabytes

 

Usage (in MB, updates every 8 hours)Data (MB) member has access to
1.0511,721,083.86

 

To sum up I want to extract Usage (in MB, updates every 8 hours) which in the example is  1.05

 

Kind regards

 

  • DB-Des's avatar
    DB-Des
    Icon for Dropbox Engineer rankDropbox Engineer

    Hi adsalguero,

     

    I'll be happy to help with any issues you're having with the Dropbox API, but I'll need some more information. Could you clarify what you mean by "But I only get "Data (MB) member has access to"?

     

    Just to confirm, the /users/get_space_usage endpoint returns only "used" and "allocated" space when the user is tagged as ".individual". For members of a team, you receive two "used" properties. The top level "used" property is the user's total space usage, while the "used" property within the "allocation" object property is the total space currently used by the user's team.

     

    In the code snippet you provided, you are calling users_get_space_usage() twice on the same user. You are also assigning the top level "used" property to both used and used_bytes variables, so it would be expected for these values to be the same:

     

    ...
    account_info = user_dbx.users_get_space_usage()
    used_bytes = account_info.used
    ...
    account_info = user_dbx.users_get_space_usage()
    used = account_info.used
    ...

     

     

    • adsalguero's avatar
      adsalguero
      Explorer | Level 4

      Good morning,

      We are now using the data provided by the Member Data Report, which I extract from the Dropbox Business reports. This report includes two columns: “Usage (in MB, updates every 8 hours)” and “Data (MB) member has access to.” The first column represents the space used by the user, while the second column shows the space that the user can see. Therefore, when I said, “But I only get ‘Data (MB) member has access to,’” I meant that I cannot retrieve the space used by a particular user.

      For example:

      User 1 has 30 MB of their own storage, not shared with anyone else. The same user is also in a shared folder or team folder and can see 3 TB of files. I want to get the 30 MB, but no matter which code I use, I get 3 TB.

      Using:

      user_dbx = dbx_team.as_user(specific_member['team_member_id'])
      account_info = user_dbx.users_get_space_usage()

      Shouldn’t this be the data related to “Usage (in MB, updates every 8 hours)”?

       

       

       

      Regards

       

       

      • DB-Des's avatar
        DB-Des
        Icon for Dropbox Engineer rankDropbox Engineer

        adsalguero

         

        Thank you for clarifying. The value stored in the "user_within_team_space_used_cached" property should match the value in the "Usage (in MB, updates every 8 hours)" column.

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API

Make connections with other developers

795 PostsLatest Activity: 2 days ago
194 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!