Select to view content in your preferred language

'Add members and notify them via email' in Hub through python api

946
4
12-07-2023 11:41 AM
SFM_TravisBott
Frequent Contributor

Question is essentially the title: is it possible to create accounts using the python api that's a replication of the 'Add members and notify them via email' style used in the GUI (see below)?

 

SFM_TravisBott_0-1701977185873.png

 

Our workflow is going to involve ingesting a list of hundreds of names from a survey, verifying them, and then creating hub community accounts. The preference would be to do so in a way that lets the user set their own password rather than provisioning them one. 

I've been able to create users just fine, and then send a notification email just fine, but I don't like how the process is separate and the fact that a notification email comes from me, rather than the ArcGIS Online system. Examples below:

 

#Define User
first_name = 'First'
last_name = 'Last'
email = 'First.Last@fake.com'

#Create user
new_user = gis.users.create(
    username = f'{first_name}_{last_name}_Community',
    password = 'testTest123',
    firstname = first_name,
    lastname = last_name,
    email = email,
    credits = 50,
    role = 't8qahvxvKEh6uNyT',
    user_type = 'creatorUT',
    groups = '<987ce15a07694fa6bf9ec45cd6241b7b>'
)

#Send notification
userList = []
userList.append(new_user)
messageSubject = 'This is a test message from AGOL'
messageMessage = 'This is the plain text message that we are sending. Check it out.'

gis.users.send_notification(userList, subject = messageSubject, message = messageMessage, type = 'email')

 

 

It would seem that just using the .create() method could generate the GUI-style email, as, according to the documentation, there's an 'email_text' argument (see below). However, when attempting this I get an error saying that the 'email_text' argument is unexpected. 

create(usernamepasswordfirstnamelastnameemailroledescription=Noneprovider='arcgis'idp_username=Nonelevel=2thumbnail=Noneuser_type=Nonecredits=- 1groups=Noneemail_text=None)

 

 

emailText = 'This is a test email! You have been invited to join this community extravaganza!'

new_user = gis.users.create(
    username = f'{first_name}_{last_name}_fhsz',
    password = 'testTest123',
    firstname = first_name,
    lastname = last_name,
    email = email,
    credits = 50,
    role = 't8qahvxvKEh6uNyT',
    user_type = 'creatorUT',
    groups = '<987ce15a07694fa6bf9ec45cd6241b7b>',
    email_text = emailText
)

 

 

SFM_TravisBott_1-1701977912380.png

Any help would be appreciated. It would be much better if we could mimic the GUI-style sending of an email, rather than creating the usernames and then sending them an email to try to log in. 

0 Kudos
4 Replies
PeterKnoop
MVP Regular Contributor

Wonder if you might be using a pre-2.2.0 version of the ArcGIS for Python API, which would not include the  email_text parameter? (What's new in version 2.2.0?)

0 Kudos
SFM_TravisBott
Frequent Contributor

@PeterKnoop You were right. After faffing through upgrading Pro, getting my python environments switched out (since Pro wouldn't accommodate updating my previous ones), I now have the updated 2.2 version of the arcgis module which allows the email parameter. 

So far it successfully created the account but there's not an email in sight. So I revert to my original question: is something like 'add members and notify via email' possible?

0 Kudos
rob_hewy
Regular Contributor

Did you this to work?

I am using 2.3.0.3 and no email is sent.

Is there a setting in the portal that needs to be flipped?

0 Kudos
rob_hewy
Regular Contributor

What just worked for me was:

  1. Create the user
    • gis.users.create(**create_user_dict)
  2. Send a notification
    • gis.users.send_notification(username, subject, message, type='email')
 
0 Kudos