<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Query Users by Category in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1258264#M50353</link>
    <description>&lt;P&gt;Hi Josh, I found this in the same docs section, right below assign_categories and thought I'd try this first since the .categories command works on my currently installed version.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Victoria_0-1676413549309.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62873i04B867224F7B5544/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Victoria_0-1676413549309.png" alt="Victoria_0-1676413549309.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm trying to follow the usage example 1. Right now, my code looks like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# testing on 1 user first: 
uncategorized_users = gis.users.search('categories:null', max_users=1)
user_categories[0] = ["/Categories/Pets"]

for user in uncategorized_users:
    list_index = 0
    user.categories = user_categories[list_index]
    ++list_index&lt;/LI-CODE&gt;&lt;P&gt;The code runs without any errors but the user isn't assigned the new category. The docs says .categories can be used for getting/setting so I'm not sure what's wrong...&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2023 22:31:18 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2023-02-14T22:31:18Z</dc:date>
    <item>
      <title>Python Query Users by Category</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257742#M50326</link>
      <description>&lt;P&gt;Hello, I have 2 questions about accessing users and their assigned categories in ArcGIS Online through python:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I'm trying to query all the users who haven't been assigned a category. This is what I first tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;users = gis.users.search(query='categories:""', max_users=1000)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It returned users who weren't categorized as well as 2 full user categories. Is this the incorrect method of searching for unassigned users? I also tried searching with query='None' but the result was an empty list.&lt;/P&gt;&lt;P&gt;The next thing I tried was using NOT in my filters. My logic was to use search(NOT (Category A OR Category B OR Category C)), in order to find the users without a category. I was trying to follow the California NOT Imagery examples here&amp;nbsp;&lt;A href="https://doc.arcgis.com/en/arcgis-online/reference/advanced-search.htm" target="_blank" rel="noopener"&gt;https://doc.arcgis.com/en/arcgis-online/reference/advanced-search.htm&lt;/A&gt;&amp;nbsp;but am getting a Syntax Error: invalid syntax.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;users = gis.users.search(query='categories:""' NOT 'categories:"/Categories/Pets"', max_users=1000)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could I ask how to search for users without a category assigned to them?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Is there a way to assign users a category through python? I couldn't find any documentation on how to do this through the API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 16:06:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257742#M50326</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-14T16:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Python Query Users by Category</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257748#M50327</link>
      <description>&lt;P&gt;Not sure but would it work to return all users then NOT IN compare against the category list?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 22:40:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257748#M50327</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2023-02-13T22:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python Query Users by Category</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257966#M50337</link>
      <description>&lt;P&gt;I was trying that on a smaller scale and my syntax works now but the query is still returning all the users, regardless of category. This is the boolean I'm using:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;users = gis.users.search('categories:"" NOT "/Categories/Pets"', max_users=1000)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 14:26:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257966#M50337</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-14T14:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Python Query Users by Category</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257972#M50338</link>
      <description>&lt;P&gt;In AGOL, this is a built-in feature:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1676384720985.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62801i356F7BDA443496EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1676384720985.png" alt="jcarlson_0-1676384720985.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And if you watch the URL parameters when you click this, you can see that the supplied query is&lt;/P&gt;&lt;PRE&gt;...&amp;amp;categories=["_none_"]&lt;/PRE&gt;&lt;P&gt;But oddly, if you are using the search query string, it's the literal word "null". Maybe just a difference in how the Python API and the REST endpoint interpret things?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_1-1676384980574.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62802iDD61CFAC6400EC51/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_1-1676384980574.png" alt="jcarlson_1-1676384980574.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Anyway, the point is you can query for non-categorized members. And according to &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#usermanager" target="_blank" rel="noopener"&gt;the API docs&lt;/A&gt;, you can assign categories easily enough.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;assign_categories&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;EM&gt;&lt;SPAN class=""&gt;users&lt;/SPAN&gt;&lt;/EM&gt;, &lt;EM&gt;&lt;SPAN class=""&gt;categories&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Adds categories to &lt;A title="arcgis.gis.User" href="https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.User" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;users&lt;/SPAN&gt;&lt;/A&gt;.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Parameter&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Description&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;users&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Required list of &lt;A title="arcgis.gis.User" href="https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.User" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;User&lt;/SPAN&gt;&lt;/A&gt; objects to categorize.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;categories&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Required string defining the categories to add to each user in the users argument list.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 14 Feb 2023 14:31:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257972#M50338</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-02-14T14:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Python Query Users by Category</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257986#M50339</link>
      <description>&lt;P&gt;Hi Josh, the null search query worked perfectly. Thank you so much! For the assign_categories command, I'm getting an Unresolved Reference 'assign_categories' error. When I run the code, there's a NameError: name 'assign_categories' is not defined.&amp;nbsp;I checked out the documentation you sent and used it with the user and category parameters. Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 14:54:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257986#M50339</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-14T14:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python Query Users by Category</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257993#M50340</link>
      <description>&lt;P&gt;Are you running your code in AGOL, or locally? You may want to check what version of the &lt;STRONG&gt;arcgis&lt;/STRONG&gt; module is currently installed in the env you're using.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 14:57:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1257993#M50340</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-02-14T14:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python Query Users by Category</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1258040#M50343</link>
      <description>&lt;P&gt;I'm running it while establishing a connection and logging into AGOL. I ran the command arcgis.__version__ before connecting and my version is 1.9.0 but the release notes has the method in 2.1.0, so I'll look into updating mine.&lt;/P&gt;&lt;P&gt;A follow-up question:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Victoria_0-1676390331270.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62824iCDA4A01B25751BB5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Victoria_0-1676390331270.png" alt="Victoria_0-1676390331270.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The assign_categories documentation is under the UserManager class. When accessing something from this class, do you need a line manager = arcgis.gis.UserManager to then access methods as manager.assign_categories(), for example?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 16:04:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1258040#M50343</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-14T16:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python Query Users by Category</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1258054#M50345</link>
      <description>&lt;P&gt;Per the docs:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;This class is not created by users directly. An instance of this class, called ‘users’, is available as a property of the Gis object. Users call methods on this ‘users’ object to manipulate (create, get, search, etc) users.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So just call gis.users.assign_categories, and pipe in your list of uncategorized folks!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 16:20:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1258054#M50345</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-02-14T16:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Python Query Users by Category</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1258264#M50353</link>
      <description>&lt;P&gt;Hi Josh, I found this in the same docs section, right below assign_categories and thought I'd try this first since the .categories command works on my currently installed version.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Victoria_0-1676413549309.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62873i04B867224F7B5544/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Victoria_0-1676413549309.png" alt="Victoria_0-1676413549309.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm trying to follow the usage example 1. Right now, my code looks like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# testing on 1 user first: 
uncategorized_users = gis.users.search('categories:null', max_users=1)
user_categories[0] = ["/Categories/Pets"]

for user in uncategorized_users:
    list_index = 0
    user.categories = user_categories[list_index]
    ++list_index&lt;/LI-CODE&gt;&lt;P&gt;The code runs without any errors but the user isn't assigned the new category. The docs says .categories can be used for getting/setting so I'm not sure what's wrong...&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 22:31:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-query-users-by-category/m-p/1258264#M50353</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-02-14T22:31:18Z</dc:date>
    </item>
  </channel>
</rss>

