Hi, I would like to query our portal for group items by category.
After loading the portal and finding the group by id, I am giving the group to this function as group0:
const getLayers = async (group0: any) => {
let queryParams = {
query: `categories: ["/Categories/CDC Social Vulnerability Index/Theme 1: Socio-economic"]`,
}
const { results } = await group0.queryItems(queryParams )
return results
}
I have tried several iterations of this search string. If I am only searching one category level (/Categories/ALICE Households), it works , but if I go into a nested category (like Theme 1 here), it returns all of the layers in the group.
I have tried categories: and groupCategories:, with curly braces, with brackets, with no braces, just a string, with quotes and without. Has anyone had any success fetching layers that have been categorized in a portal group in a nested category schema?
With gratitude,
Michelle
Solved! Go to Solution.
Hi @MichelleStuart -
Instead of using the query property, have you tried using the PortalQueryParams categories property? This takes a string or an array of strings that can be formatted like so:
let queryParams = {
categories: [
["/Categories/Trending/New and noteworthy", "/Categories/Basemaps/Reference maps/Test category"]
]
};
If attempting to get items in a subcategory, be sure to add those category folders the to full path.
Here's an example CodePen that queries two different categories that contain sub categories: https://codepen.io/laurenb14/pen/wvOYvWv?editors=1000
Hope this helps!
Hi @MichelleStuart -
Instead of using the query property, have you tried using the PortalQueryParams categories property? This takes a string or an array of strings that can be formatted like so:
let queryParams = {
categories: [
["/Categories/Trending/New and noteworthy", "/Categories/Basemaps/Reference maps/Test category"]
]
};
If attempting to get items in a subcategory, be sure to add those category folders the to full path.
Here's an example CodePen that queries two different categories that contain sub categories: https://codepen.io/laurenb14/pen/wvOYvWv?editors=1000
Hope this helps!
Thank you Lauren! This worked. I really appreciate your help.