Reassign credits in ArcGIS Online for users using Python API

162
2
Jump to solution
04-16-2021 08:52 AM
JoeWeyl
Occasional Contributor

Hi -

We had a couple of times where our user credit default assignment in ArcGIS Online wasn't able to be applied to new users because we were temporarily out of credits. Therefore, they got assigned the maximum, instead of our default allocation. We have over 1400 users in ArcGIS Online, and this has happened a few times (so in the neighborhood if hundreds of users with the wrong credit amount).

I tried writing a loop to see if users had unlimited credits, but that doesn't appear to be working. I can report the number of credits a user has assigned to them but I don't see a way to check the current allocation?

I used  example code to try and figure this out, but I couldn't find anything in the documentation about what I am trying to do? 

Here is my example:

from arcgis.gis import GIS
gis = GIS("https://*.maps.arcgis.com", "userid", "pwd")

gis.admin.credits.credits

gis.admin.credits.is_enabled

cm = gis.admin.credits

and here is the loop I tired, as you can see it is incomplete because it doesn't work and I can't find what I need to solve it. 

source_users = gis.users.search('!esri_ & !admin')
for user in source_users:
if cm.???  == -1:
#print(user.username + "\t:\t" + str(user.availableCredits))
cm.allocate(user,10)
cm

Nothing is returned, but where I have the question marks are what I know is incorrect. 

Anyone have any insight on this? 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
HamishMorton
Esri Contributor

Hi Joe,

How about this?

from arcgis.gis import GIS

gis = GIS("home") # Initiate GIS object

cm = gis.admin.credits # Initate credit manager object

source_users = gis.users.search(query=None, outside_org=False, max_users=400) # Return all users from ArcGIS Online org

for user in source_users:
    
    # If a users credit limit is unlimited, change it to 10
    if user.assignedCredits == -1 and user.role != "org_admin":
        
            cm.allocate(user.username, 10)
            
            print("Allocated {} 10 credits".format(user.username))

 

View solution in original post

2 Replies
HamishMorton
Esri Contributor

Hi Joe,

How about this?

from arcgis.gis import GIS

gis = GIS("home") # Initiate GIS object

cm = gis.admin.credits # Initate credit manager object

source_users = gis.users.search(query=None, outside_org=False, max_users=400) # Return all users from ArcGIS Online org

for user in source_users:
    
    # If a users credit limit is unlimited, change it to 10
    if user.assignedCredits == -1 and user.role != "org_admin":
        
            cm.allocate(user.username, 10)
            
            print("Allocated {} 10 credits".format(user.username))

 

View solution in original post

JoeWeyl
Occasional Contributor

Thank you, that was exactly what I was missing. 

0 Kudos