Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.81k stars 1.08k forks source link

UserManager module, Update won't allow user category update #1482

Closed MSLTrebesch closed 1 year ago

MSLTrebesch commented 1 year ago

Describe the bug using the the UserManager module with Update. when specifying the user categories (they exist) in a list per documentation, Update throws error.

To Reproduce Steps to reproduce the behavior:

u_user = s_user.update(tags="Student Lab", categories = ['Student Lab'])

s_user is a created user object

error:

update() got an unexpected keyword argument 'categories'

Screenshots If applicable, add screenshots to help explain your problem.

Expected behavior expected already existing user category of "Student Lab" to be applied to the provided user object

Platform (please complete the following information):

Additional context Running in ArcGIS Online Notebook as an admin user to my subscription

achapkowski commented 1 year ago

You need to use the UserManager.assign_categories method.

1). Define the categories

>>> category_dict = {"memberCategorySchema": [
                                               {"title": "Categories",
                                               "categories": [
                                                              {"title": "Office Location"},
                                                              {"title": "Department"}
                                                             ]
                                               }
                                             ]
                     }
>>> gis.users.categories = category_dict

2). Assign the categories

>>> gis.users.assign_categories(users=[gis.users.me], categories=['Office Location'])
MSLTrebesch commented 1 year ago

You need to use the UserManager.assign_categories method.

1). Define the categories

>>> category_dict = {"memberCategorySchema": [
                                               {"title": "Categories",
                                               "categories": [
                                                              {"title": "Office Location"},
                                                              {"title": "Department"}
                                                             ]
                                               }
                                             ]
                     }
>>> gis.users.categories = category_dict

2). Assign the categories

>>> gis.users.assign_categories(users=[gis.users.me], categories=['Office Location'])

Interesting, what if my categories are already defined via the AGOL interface? Do I need to define the categories?

also, when calling 'assign_categories' I still get this error, when used against my user object list (using 'me' for simplicity): ----> 1 gis.users.assign_categories(users=[gis.users.me], categories=['Student Lab'])

AttributeError: 'UserManager' object has no attribute 'assign_categories'

Same with:

cat_users = gis.users.search("student_user")
cat_users

>>> [<User username:student_user_1>, <User username:student_user_2>]
gis.users.assign_categories(users=cat_users, categories=["Student Lab"])
>>> AttributeError: 'UserManager' object has no attribute 'assign_categories'
achapkowski commented 1 year ago

What version of the python API are you using? This is newer functionality

MSLTrebesch commented 1 year ago
  • Python API Version '2.0.1'

What's available in our current AGOL environment

MSLTrebesch commented 1 year ago

@achapkowski yes. I understand the AGOL Notebook API version is behind the functionality in the current API. Missed that. (I mistakenly thought they were synchronizing, or closer)