Creating new user via ArcGIS API for Python

1265
11
02-17-2020 10:56 PM
PhilippeRieffel1
Occasional Contributor

Hey all, 

i am trying to automate the creation of named users on arcgis online. I am basically using the code from the example notebooks. And it always fails

the gis object is created with an administrator connection, and i tested it with version 1.7.0 as well, same error. So, my question would be, is there any way to get a more detailed response from the api, like the actual response of the rest call or something? Or in general, what am i doing wrong here?

Thanks for your input.

0 Kudos
11 Replies
WilliamCraft
MVP Regular Contributor

Can you provide a bit more of the preceeding code to give a bit more context so we can see where you create the GIS object?  

0 Kudos
PhilippeRieffel1
Occasional Contributor

Hey William, thanks for taking the time to look at my problems

The gis object is created as follows:

I tried the gis.user, but i am pretty sure, that users is correct, because the API Reference lists the create() method as a method of the user-manager class (users) and not the user class. See arcgis.gis module 

So from my point of view, the method/syntax is correct, but it does not work....

0 Kudos
WilliamCraft
MVP Regular Contributor

Yes, your syntax does appear to be correct.  Can you remove all of the parameters in your create command that follow the role='org_user' portion?  You might try trimming that section down a bit to get to the bare minimum parameters required for creating a user.  It's possible that some of those parameters don't apply to AGOL; only to Portal.  

0 Kudos
PhilippeRieffel1
Occasional Contributor

Unfortunately, that did not work

0 Kudos
WilliamCraft
MVP Regular Contributor

Also, according to the documentation, the required user_type parameter value must either be 'creator' or 'viewer'.  

0 Kudos
PhilippeRieffel1
Occasional Contributor

Changing the user_type to 'Creator' did not change anything

0 Kudos
WilliamCraft
MVP Regular Contributor

Interesting.  And you're absolutely sure there isn't already a user in AGOL named 'DemoUser'?  If not, I'm out of ideas.  

0 Kudos
HuubZwart
Occasional Contributor

It looks like the API reference is actually wrong here. It states the username needs to be unique in Portal, but in my experience for AGOL it needs to be unique not only for the active AGOL environment but for all environments

I ran into the same issue in an AGOL environment with only a single user. With the above procedure I couldn't create a user with the username "username" (arbitrary, 6-24 characters). Changing the username to "username_SOMETHING" made it work for me.  

This is reproducible creating a user by administrating AGOL through a browser and browsing to organization/users - creating a username that exists outside the active AGOL environment is impossible (username already exists). 

0 Kudos
JPGarCar
New Contributor

Did you find a solution to your problem? I am having the same exact issue, I have tried everything and I can't get it to work. Would really appreciate your input!

0 Kudos