Dec 7, 2021 11:47 PM - edited Dec 8, 2021 12:08 AM
Hello,
I am writing a custom module to display specific products on a page. I want to filter all my products based on a tag, in this case the `ip__shopify__tags` property.
I am trying to write a query like this:
{% set products = crm_objects(dynamic_page_crm_object_type_fqn, "ip__shopify__tags__contains=215","ip__shopify__tags") %}
But it does not filter them, it returns all 81 of my products and I'm expecting 25.
I tried modifying the query to use "in", like this: `ip__shopify__tags__in=215`
But it returned 0 products.
I should note that when I remove the query param and simply request all my products I get 81 results.
I know this string querying should work in principle, because it is working fine via the REST api using the CONTAINS_TOKEN operator:
```
POST https://api.hubapi.com/crm/v3/objects/products/search
body:
Dec 8, 2021 6:00 PM
Hello,
I am writing a custom module to display specific products on a page. I want to filter all my products based on a tag, in this case the `ip__shopify__tags` property (I'm building a shop using the Shopify Integration).
I am trying to write a query like this:
{% set products = crm_objects(dynamic_page_crm_object_type_fqn, "ip__shopify__tags__contains=215","ip__shopify__tags") %}
But it does not filter them, it returns all 81 of my products and I'm expecting 25.
I tried modifying the query to use "in", like this: `ip__shopify__tags__in=215`
But it returned 0 products.
I should note that when I remove the query param and simply request all my products I get 81 results.
I know this string querying should work in principle, because it is working fine via the REST api using the CONTAINS_TOKEN operator:
```
POST https://api.hubapi.com/crm/v3/objects/products/search
body:
Dec 8, 2021 6:38 PM
The in operator is documented as a valid operator in this link.
Also what about this bit:
ip__shopify__published_at__not_null=
Seems a bit funky containing the = sign like this.
Dec 8, 2021 6:55 PM
@miljkovicmisa wrote:The in operator is documented as a valid operator in this link.
Also what about this bit:
ip__shopify__published_at__not_null=
Seems a bit funky containing the = sign like this.
Yes, I know the in operator is valid, I'm just not sure what it does or how to get it to work.
I thought that = sign part was funky too, but it works. Whether I include it or not makes no difference, I get the same query results either way.
I appreciate you taking the time to help troubleshoot @miljkovicmisa .
Dec 8, 2021 4:24 PM
Hello @jplew , 👋@dennisedson !
Thank you for writing in the forum, it seems that the contains
query operator is only applicable for multi-valued properties, as per the documentation. Have you tried the in
operator?
If my answer was helpful please mark it as a solution.
Dec 8, 2021 5:56 PM
Hi @miljkovicmisa ,
thanks for the suggestion. In my original post I mentioned that I tried "in" already and it returns 0 results. So it's either buggy or not what I'm looking for.
The documentation is not clear either on its intended usage, nor does it give any examples. For example how do I search for a string with spaces? Which one of these?
I can't verify these because nothing works.
Is it possible to bypass the clunky `crm_objects` method altogether and invoke the Hubspot API? I don't see why HubL coders or custom module builders should be denied the opportunity to use the API, which is far better documented than the native HubL functions.
Dec 8, 2021 6:01 PM
@jplew I also see another thing and I'm not sure if that causes the issue but the internal name of the property seems to have double underscores which is the way that hubspot differrentiates the operator from the property name, so maybe that's why it's buggy, maybe try it with another property and see if it works okay, properties should have single underscores, something like the following:
ip_shopify_tags__in=dry trimmer
P.S.: The query should take care of the spaces accordingly in its internal call so I wouldn't worry about that.
Dec 8, 2021 6:16 PM
That's a clever suggestion. I don't think that's the problem however, since I've used operators on other properties with a double-underscore. When I use the "in" operator with another property I still get 0 results. My actual queries look like this:
0 results
"ip__ecomm_bridge__source_app_id__contains=51381&ip__shopify__published_at__not_null=&limit=200&name__in=215"
0 results
"ip__ecomm_bridge__source_app_id__contains=51381&ip__shopify__published_at__not_null=&limit=200&shopify_slug__in=215"
0 results
"ip__ecomm_bridge__source_app_id__contains=51381&ip__shopify__published_at__not_null=&limit=200&ip__shopify__tags__in=215"
81 results
"ip__ecomm_bridge__source_app_id__contains=51381&ip__shopify__published_at__not_null=&limit=200"
Is the "in" operator documented anywhere?
Dec 8, 2021 4:02 PM
@miljkovicmisa , any chance you could help out here?