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!
Solved! Go to Solution.
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:
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 - 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!
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 - thanks very much for this, that's really useful!
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.