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 xyz,yyy are my username and password.
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="comment token"># User name is case sensative as is password!</SPAN>
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://geodatainstitute.maps.arcgis.com"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"xyz"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"yyy"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># https://www.arcgis.com</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>gis<SPAN class="punctuation token">.</SPAN>users<SPAN class="punctuation token">.</SPAN>counts<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'user_type'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># This line runs OK</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"create a new user"</SPAN><SPAN class="punctuation token">)</SPAN>
newuser <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>users<SPAN class="punctuation token">.</SPAN>create<SPAN class="punctuation token">(</SPAN>username<SPAN class="operator token">=</SPAN><SPAN class="string token">'testuserxxx'</SPAN><SPAN class="punctuation token">,</SPAN> password<SPAN class="operator token">=</SPAN><SPAN class="string token">'q1w2e3r4t5y6,.<>'</SPAN><SPAN class="punctuation token">,</SPAN> firstname <SPAN class="operator token">=</SPAN><SPAN class="string token">'Firstxxx'</SPAN><SPAN class="punctuation token">,</SPAN> lastname <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Secondsxxx'</SPAN><SPAN class="punctuation token">,</SPAN> email <SPAN class="operator token">=</SPAN> <SPAN class="string token">'test@test.com'</SPAN> <SPAN class="punctuation token">,</SPAN> role<SPAN class="operator token">=</SPAN><SPAN class="string token">'org_user'</SPAN><SPAN class="punctuation token">,</SPAN> level<SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> provider <SPAN class="operator token">=</SPAN> <SPAN class="string token">'arcgis'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> newuser <SPAN class="keyword token">is</SPAN> None<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"FAILED!"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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