It works now!
It seem .setRoles does not work.
.addRole does.
I had tried importing java string, and then making my string for the role into a java string. Well it sort of worked, but then I got an error that some kind of python object could not be converted.
So then I went with addRole.
Thanks so much for all the help.
# List of emails to check against
email_list = ["email1@example.com", "email2@example.com", "email3@example.com"]
# Retrieve all users
users = system.user.getUsers('default')
# Loop through each user
for user in users:
# Get contact info for the user
contacts = user.getContactInfo()
# Check if any contact is an email in the email_list
for contact in contacts:
if contact.contactType == "email" and contact.value in email_list:
# Get the user's current roles
current_roles = user.getRoles()
# Append the role if not already present
if "roleThatExists" not in current_roles:
print user
user.addRole("roleThatExists")
response =system.user.editUser("default", user)
print response.getErrors()