Knowledge Drop

Steps for Creating a New User (email creds, role, group) via Python SDK


Userlevel 5

Last tested: Nov 8, 2020
 

There are a few steps to creating a new user with the api/sdk. We have to first create the user, which gives us an ID -> we then write the credentials for the user (think email, LDAP, etc.) -> from there we can assign that user to a group, assign them roles, etc.

Below is a script that includes all the necessary sdk calls, this is all wrapped in a single function to call for convenience:

import looker_sdk

from looker_sdk import models

 

### Create User, Write Email Creds, Assign Roles and Groups ###

 

# initialize sdk

sdk = looker_sdk.init40(config_file='looker.ini')

 

firstName = "Spike"

lastName = "Spiegel"

emailName = "swordfishII@somegalaxy.com"

roles = [184,36]

group = 76

 

### function to create new user ###

def newUser(fname, lname, email_address, roleIds, groupId):

 

# create user with id

new_user_obj = sdk.create_user(body=models.WriteUser(

first_name=fname, last_name=lname

))

 

# assign email credentials

user_with_email = sdk.create_user_credentials_email(user_id=new_user_obj.id, body=models.WriteCredentialsEmail(

email=email_address

))

 

# assign user to role

user_with_role = sdk.set_user_roles(user_id=new_user_obj.id, body=roleIds)

 

# assign user to group

user_with_group = sdk.add_group_user(group_id=groupId, body=models.GroupIdForGroupUserInclusion(

user_id=new_user_obj.id

))

 

# send account setup email

send_new_user_email = sdk.create_user_credentials_email_password_reset(user_id=new_user_obj.id)

 

### create new user ###

newUser(firstName, lastName, emailName, roles, group)

 

This content is subject to limited support.                

 

 


0 replies

Be the first to reply!

Reply