User Delete - not licensed by user error

2418
7
Jump to solution
05-07-2021 03:29 PM
AdamMesser1
New Contributor III

Our code for deleting inactive users on AGOL is failing on the user.delete() command after upgrade to Pro 2.7.0 using the python api 1.8.4. The final return is "Exception: not licensed by user (Error Code: 400)" with full return in attached file. These users do not have content or own groups or have any special licensing. To verify, a new test user with no content, etc. was created and exhibited the same issue. Upgraded to Pro 2.7.3 and api 1.8.5 did not solve the issue. Going back to the base python 3.7.9 install from the ve also did not change the error. As it seems related to entitlements, I added a license to the user to see if the error changed, it didn't. The user can be deleted manually via AGOL, and a different machine running Pro 2.3.2 and I believe api 1.6.2, can run this command without error. None of our other python api commands seem to be failing. Ideas on what I'm missing?

Tags (2)
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

File an "Issue" on the arcgis-api site

Issues · Esri/arcgis-python-api (github.com)

 


... sort of retired...

View solution in original post

7 Replies
DanPatterson
MVP Esteemed Contributor

File an "Issue" on the arcgis-api site

Issues · Esri/arcgis-python-api (github.com)

 


... sort of retired...
AdamMesser1
New Contributor III

Will do. Thanks @DanPatterson 

0 Kudos
ChristopherSchreiber
Occasional Contributor II

Thanks for posting about this! I ran into the same issue! 

As a workaround, you could hit the REST API directly. You can do this by using the 'Requests' library and Esri's REST API.

 

 

 

 

token = gis._con.token
url = '{0}/sharing/rest/community/users/{1}/delete?f=json&token{2}'.format(gis.url, username, token)
deleteAgolUser = requests.post(url)
print("Delete User Results for user {0}: {1}".format(username, deleteAgolUser.text)

 

 

 

 

"token" in the above snippet, gets the token that is generated when you authenticate using GIS. See this post for more details. 

The 'print' statement is just something that I use, feel free to ignore it!

 

I hope this helps someone! 

 

Chris

CarlVricella
New Contributor III

Url is formatted slightly wrong, should be: 

url = '{0}/sharing/rest/community/users/{1}/delete?f=json&token={2}'.format(gis.url, username, token)

 

Also this is python 3 so you would want to use an f string instead

url = f'{gis.url}/sharing/rest/community/users/{username}/delete?f=json&token={token}'
0 Kudos
CCGT_UAV
New Contributor II

According to ArcGIS API reference , "you can not delete a user in Portal if that user owns groups or items and/or is assigned an application bundle. If you specify someone in the reassign_to argument, then items and groups will be transferred to that user. If that argument is not set then the method will fail if the user has items or groups that need to be reassigned." 

Moreover, all assigned licenses to a user must also be revoked before you can delete the user. This is missing in the API Ref. 

In short, before you can delete a user using ArcGIS API you need,

1- Remove or transfer the user's all items and owning groups 

2- Remove all assigned app bundles.

3- Revoke all assigned licenses. 

 

Cheers,

CCGT_UAV

0 Kudos
AdamMesser1
New Contributor III

Correct CCGT_UAV, however, I indicated that I checked those and created a test user with no privileges to verify. Thanks for pointing folks to the API reference.

MJBiazar
Esri Contributor

Hi all,

It seems like the "Error Code: 400 not licensed by user" when trying to delete a member was due to a defect in ArcGIS API for Python (1.8.X). 

This has been addressed in 10.9 version. 

0 Kudos