Unable to create a new user via ArcGIS API

1642
3
Jump to solution
01-14-2020 06:58 AM
DuncanHornby
MVP Notable Contributor

All,

I am exploring some scripting of the ArcGIS API for Python in the hope I can automate some future scenario. I have an administrator role on ArcGIS Online.

All I am trying to do is create a user that is a viewer as we have some unused viewer licenses to test with. My code is simply this, where xxx,yyy are my username and password.

from arcgis.gis import GIS
# User name is case sensative as is password!
gis = GIS("https://geodatainstitute.maps.arcgis.com","xxx","yyy") # https://www.arcgis.com
print(gis.users.counts('user_type')) # This line runs OK
print("create a new user")
newuser = gis.users.create(username='testuserxxx', password='q1w2e3r4t5y6,.<>', firstname ='Firstxxx', lastname = 'Secondsxxx', email = 'test@test.com' , role='org_user', level=1, provider = 'arcgis')
if newuser is None:
 print("FAILED!")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

It always returns this:

create a new user
Unable to create testuserxxx
Unable to create testuserxxx
FAILED!

What am I doing wrong? I have followed the example as shown here. I have also tried connecting to https://www.arcgis.com  but I still get the same error.

Is there some setting on AGOL that needs turning on/off, have I set up the role/level correctly? If one looks at the UserManager class on the API help file it confusing indicates that user_type is a required parameter but that seems not the case?

Any help or advice would be much appreciated.

Duncan

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

Hi Adrian,

I've been playing around with my very simple code above as no one offered up any pearls of wisdom... You would think ESRI staff would be all over this. Anyway this finally worked...

newuser = gis.users.create("testuserxyz","1234567890QWERTYuio","Dumbo","Dumbo2","test@test.com",None,None,"arcgis",None,1,None,"viewer")

The issue seemed to be with the password length and characters. Try something like above.

The only other difference was that I was running the code from within the Python command line window in Pro.

Hope that helps!

View solution in original post

0 Kudos
3 Replies
AdrianHughes3
Occasional Contributor

I'm also having this issue, even when trying the example code, shown here

DuncanHornby
MVP Notable Contributor

Hi Adrian,

I've been playing around with my very simple code above as no one offered up any pearls of wisdom... You would think ESRI staff would be all over this. Anyway this finally worked...

newuser = gis.users.create("testuserxyz","1234567890QWERTYuio","Dumbo","Dumbo2","test@test.com",None,None,"arcgis",None,1,None,"viewer")

The issue seemed to be with the password length and characters. Try something like above.

The only other difference was that I was running the code from within the Python command line window in Pro.

Hope that helps!

0 Kudos
AdrianHughes3
Occasional Contributor

Thanks Duncan

I still get the same error with your code, running from both jupyter notebook and python window in pro

0 Kudos