pyDOMO Create users based on existing dataset
Hi,
Im trying to automate our creation of users and assign role dynamically based on our existing dataset in DOMO.
Im new to pyDOMO and currently following samples below:
user_list = pd.read_csv('UserList.csv')
def add_user_list(ul,domo_object,invite=False):
ur = CreateUserRequest()
users_created = []
for index, row in ul.iterrows():
ur.name = row['Full Name']
ur.email = row['Email']
ur.role = row['Role']
users_created.append(domo_object.users.create(ur,invite))
return(users_created)
created_users = add_user_list(user_list,domo)
It works well and however is there a way to loop the details in dataset and not in excel file?
Im currently exploring dataset.py but I dont know how to get the values for the columns, it only returns count
https://github.com/domoinc/domo-python-sdk/blob/master/examples/dataset.py
Best Answer
-
Thanks! @GrantSmith Got it working.
heres my code for reference:
#check dataset based on specified dataset_id retrieved_dataset = domo.datasets.get(dataset_id) #export data retrieved to a string csv_download = datasets.data_export(retrieved_dataset['id'], include_csv_header) #transform string to dataframe user_list = pd.read_csv(StringIO(csv_download)) #loop within the user_list and read the fields and assign to DOMO objects. def add_user_list(ul,domo_object,invite=False): ur = CreateUserRequest() users_created = [] for index, row in ul.iterrows(): ur.name = row['Employee Name'] ur.email = row['Email'] ur.role = 'Participant' users_created.append(domo_object.users.create(ur,invite)) return(users_created) created_users = add_user_list(user_list,domo) all_users = domo.users.list(500,0)
1
Answers
-
Hi @cedvill00
You'll want to look at the ds_query method to query domo datasets:
- ds_query - allows you to send a query to a data set, Domo will evaluate that query and sends the results back as a list or a tibble
This will get you a result set as a dataframe to loop over like your existing method.
Alternatively you can use ds_data_export to export an entire dataset to an in-memory string and then user pd.read_csv to convert it to a dataframe and then use your existing looping methodology. There's an example on this way in their GitHub example: https://github.com/domoinc/domo-python-sdk/blob/master/examples/dataset.py#L48
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
Thanks! @GrantSmith Got it working.
heres my code for reference:
#check dataset based on specified dataset_id retrieved_dataset = domo.datasets.get(dataset_id) #export data retrieved to a string csv_download = datasets.data_export(retrieved_dataset['id'], include_csv_header) #transform string to dataframe user_list = pd.read_csv(StringIO(csv_download)) #loop within the user_list and read the fields and assign to DOMO objects. def add_user_list(ul,domo_object,invite=False): ur = CreateUserRequest() users_created = [] for index, row in ul.iterrows(): ur.name = row['Employee Name'] ur.email = row['Email'] ur.role = 'Participant' users_created.append(domo_object.users.create(ur,invite)) return(users_created) created_users = add_user_list(user_list,domo) all_users = domo.users.list(500,0)
1 -
Hi @GrantSmith
Just want to get back here instead of posting a new question.
Maybe you know the answer.
Im trying to create a user based on our custom made role.
Now , CreateUserRequest() of domo only accepts role that are defaults eg Privilege, Admin, Participant.
When I assign a different role, a role that we created, it wont accept it.
It returns error.
0 -
Have you tried passing in the id of your custom role instead of the string name?
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2 -
Have you seen the content from DP21 on using PyDomo?
https://www.domo.com/domopalooza/resources/managing-users-groups-with-pydomo
https://www.domo.com/domopalooza/resources#/all/all/data-governance/all/all/2021
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"1 -
Hi @GrantSmith,
I tried passing roleid in role already, doesn't work.
I also checked the acceptable attr, it only accepts name, email and role, no roleid.
Also for any custom made roles, the names are coming as blank for the existing users (manually created).
Compared to the ones that are domo roles.
Thanks @jaeW_at_Onyx for the reference.
that is where I got the code :)
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 622 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 744 Beast Mode
- 58 App Studio
- 41 Variables
- 686 Automate
- 176 Apps
- 453 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 395 Distribute
- 113 Domo Everywhere
- 276 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive