Select to view content in your preferred language

Python Assign User Category

989
5
Jump to solution
02-16-2023 11:16 AM
by Anonymous User
Not applicable

Hello, I'm trying to assign users that currently don't have categories new categories. I found this command screenshotted below in the docs (https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.UserManager).

Victoria_0-1676413549309.png

The docs says the categories property can be used to get or set categories. Right now, I'm able to get a user category with this code:

all_users = gis.users.search(query='*', max_users=10)
for user in all_users:
    category = user.categories
    print(category)

However, I'm trying to set a user's category and my code is:

index = 0
for user in all_users:
    user.categories = categories[index] # where categories is a list of lists, each nested list contains the corresponding user's new categories
    ++index

Nothing's happening to the user's category in ArcGIS Online when I run my code and I was wondering if anyone has had experience setting user categories with Python?

Thank you!

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
PeterKnoop
MVP Regular Contributor

I believe categories only supports getting the property for user objects. You can set a user's category using the update() method.

View solution in original post

5 Replies
PeterKnoop
MVP Regular Contributor

I believe categories only supports getting the property for user objects. You can set a user's category using the update() method.

by Anonymous User
Not applicable

Thanks Peter, I'll give this a try!

0 Kudos
by Anonymous User
Not applicable

Thanks Peter, I was having some issues with my arcgis version but once I updated it, I could use the update() method and successfully assigned categories!

0 Kudos
RobertWeber
Regular Contributor

Got it to apply finally. Here is what worked for me using the user.update()

user.update(categories = ["/Categories/States/Colorado"])

I was trying to apply a category that was nested I suppose...

zrobinson_agolpublic
Emerging Contributor

When I try to use the same code, I get an error that categories isn't a recognized argument for the update() method. But other arguments like description, name, etc. work for me. 

0 Kudos