Select to view content in your preferred language

Monitor ArcGIS Online License Allocations via API?

1020
5
Jump to solution
11-03-2023 01:11 PM
Labels (2)
TimF
by
New Contributor III

Hi,

I'm trying to draft an ArcGIS Python API script that can monitor the license allocations for our ArcGIS Online organisation.

According to the documentation there should be a 'plot' function that returns this information, but I can't figure out the syntax to get it to work.

For example, the following works:

lm = gis.admin.license.all()
print(lm)

But this doesn't:

lm = gis.admin.license.plot()
print(lm)

AttributeError: 'LicenseManager' object has no attribute 'plot'

I don't entirely understand the guidance, as there aren't any code snippets... where am I going wrong?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
EarlMedina
Esri Regular Contributor

plot() is a method on a License, not LicenseManager. So, from your example you would just grab one of the licenses returned and plot from there:

 

licenses = gis.admin.license.all()
licenses[0].plot()

 

 

This would return something like this:

EarlMedina_0-1699303675578.png

 

View solution in original post

0 Kudos
5 Replies
EarlMedina
Esri Regular Contributor

plot() is a method on a License, not LicenseManager. So, from your example you would just grab one of the licenses returned and plot from there:

 

licenses = gis.admin.license.all()
licenses[0].plot()

 

 

This would return something like this:

EarlMedina_0-1699303675578.png

 

0 Kudos
TimF
by
New Contributor III

@EarlMedina - thanks for your response, I had a feeling I was fundamentally misunderstanding how to apply it!

Having got it to work I can see this is really useful for add-on licences, such as ArcGIS Pro. I can't see User Types in it however. I perhaps incorrectly assumed 'Viewer/Editor/Creator' were a form of 'licence' and that plot would display total allocation vs seats occupied for the user types - as that is a bit of a pain to check manually. This doesn't look to be the case however. Do you know if that available via a different method? 

Thanks!

0 Kudos
EarlMedina
Esri Regular Contributor

I don't know of a specific method for this, but one way to do it would be to run a user search and then get the userLicenseTypeId (this was formerly userType so try both if you run into unexpected results in your version) value for each User object. The userLicenseTypeId values correspond to the userLicenseTypeId values described in REST API documentation:

creatorUT | editorUT | GISProfessionalAdvUT | GISProfessionalBasicUT | GISProfessionalStdUT | viewerUT | fieldWorkerUT

From there, you should have the data necessary to create your own plot/table. It's been a long while since I've had to do anything with Users/Content, but something like this should get you started:

 

import pandas as pd
from arcgis.gis import GIS

gis = GIS("https://machine.domain.com/portal", "username", "password")
users = gis.users.search('*',  max_users=1000)
df = pd.DataFrame(users)
df.userLicenseTypeId.value_counts().plot(kind='bar', title="User Type Plot")

 

For simplicity, I use the user search results directly here, but ideally you would just grab the things you actually need from the User objects (if you don't, you may notice a performance hit especially with larger results). For example:

users = [{"username": user.username, "userLicenseTypeId": user.userLicenseTypeId } for user in gis.users.search('*',  max_users=1000)]

 

Anyhow, this should yield a plot like this one:

EarlMedina_0-1699888439668.png

 

 

0 Kudos
TimF
by
New Contributor III

@EarlMedina - thanks very much for this, that's really useful!

0 Kudos
YukoOliver
New Contributor III

Hi, @EarlMedina Is this possible to get the info for enterprise portal users?  I tested it for our AGOL users and it worked great, but not for the portal users.

I'm getting an empty list. Below is the post I ran into. 

https://community.esri.com/t5/arcgis-api-for-python-questions/granting-licenses-to-new-users-gis-lic...

 

0 Kudos