Anyone have luck using the categories argument with the search? For me it isn't returning any items even though I've confirmed the item is categorized. I've tried using the full category string and the keyword. None of these return anything:
item_search = gis.content.search(query = "", categories="/a/b/c/d")
item_search = gis.content.search(query = "", categories="d")
item_search = gis.content.search(query = "", categories="[d]")
Hey, you were pretty close!
Categories takes a string or list, so form your example it would be either
item_search = gis.content.search(query="", categories=["/Categories/category_1", "/Categories/category_2"])
OR
item_search = gis.content.search(query="", categories="/Categories/test")
So, the key is just to make sure you're writing "/Categories/{your_category_name}"
Hope this helps!
SupriyaK, did you get it working? I'm having the same problem. I've tried many things, nothing works.
item_search = gis.content.search(query="", categories="/Categories/My Category")
item_search = gis.content.search(query="", categories=["/Categories/My Category"])
cat="/Categories/My Category"
item_search = gis.content.search(query="", categories=cat)
item_search = gis.content.search(query="", categories=[cat])
I had spaces in my category name, tried renaming without spaces, still nothing. Tried the query as empty string and with * wildcard, nothing.
Thanks @EarlMedina and @WilliamKyngesburye
I tried the below and still didn't have anything returned when I looped through the search content. My organization category is nested under two groups which is why I've shown the full category string as "/a/b/c/d". Those letters don't represent multiple categories but the full string of a single category that is nested.
item_search = gis.content.search(query = "", categories=["/a/b/c/d"])
To make things a bit more clear here is an example for how I am running the search and checking what the search returns.
item_search = gis.content.search(query = "owner:XXX", max_items=150, categories=["/Categories/Subgroup1/Subgroup2/Category1"])
for item in item_search:
print(item.title)
Here's what I would do next: go to he Contents page where you're assigning Categories to your items, open your browser's developer tools and switch to the Network tab, clear any existing traffic, make a nominal change to one of your items (add/remove a category), and see what the traffic reports back after you click Save. You'll be looking for an updateItems request - check what the request body for that is. It should look like this:
items: [{"abcdefghijklmnop123456789":{"categories":["/Categories/test"]}}]
There's probably some encoding to account for if your category has special characters in it.
@EarlMedina Thanks for the idea and providing the request I should look for! I used it to capture the exact string and unfortunately it is the same string I've been using all along.
I have a feeling you've tested this and are able to get this to work so I wonder if it might be because of my user type, role privileges or how I'm running the script. I've been using Notebooks in ArcGIS Online. I will see if a different user has luck running the script.