Unable to Extract Email address of users through API

pcharugu
Level 1
Unable to Extract Email address of users through API

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

0 Kudos
2 Replies
pcharugu
Level 1
Author

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

 

 

0 Kudos
sergeyd
Dataiker

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. 

 

0 Kudos