Unable to Extract Email address of users through API

pcharugu
pcharugu Registered Posts: 2 ✭✭✭

When I try to extract the user details using the following code.

import dataiku
client = dataiku.api_client()
dss_users = client.list_users()
user_list = []
# Grab list of All users without Email
for user in dss_users:
if user['enabled'] == True:
user_list.append(user['displayName'])
user_list.append(user['userProfile'])
user_list.append(user['groups'])

user_list.append(user['email'])
print (user_list)

I get an error for the line user_list.append(user['email']) saying that email field can't be detected. But if I run the line user_list.append(user) I could see a field called email for all the users. Can you help me finding out how to extract email address for the users being an admin. Attaching the necessary Pictures for your reference.


Operating system used: windows

Tagged:

Answers

  • pcharugu
    pcharugu Registered Posts: 2 ✭✭✭

    Attaching the screenshot of the needed field which I get on using user_list.append(user) instead of specific fields

  • Sergey
    Sergey Dataiker, Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS Core Concepts Posts: 365 Dataiker
    edited July 17

    Hi @pcharugu
    ,

    If you need to have a list of users from the administration group with their user profiles, email addresses, you can use this code:

    import dataiku
    import pandas as pd
    
    client = dataiku.api_client()
    dss_users = client.list_users()
    user_list = []
    
    # Grab list of All users without Email
    for user in dss_users:
        if user['enabled'] == True:
            if user['groups'] == ['administrators']:
                try: 
                    user_list.append((user['displayName'], user['userProfile'], user['groups'], user['email']))
                except:
                    break
    
    df_users = pd.DataFrame(user_list, columns=["User name", "Profile type", "User Groups", "Email address"])
    
    print(df_users)

    This will print pandas dataframe with all the details.

Setup Info
    Tags
      Help me…