Python Assign User Category

566
4
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

4 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
New Contributor III

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...