Happy Business Starts Here

Highlighted
Tutor

Is there a way to query products from the catalog applying filters?

I would like to know whether there is a way to perform a query e.g. using /v1/action/query on the product catalog. In particular I would like to retrieve a subset of th entire catalog by filtering on the product features.
I know that I can use the /v1/catalog/products GET call but for a couple of on-demand selections I would like to avoid to query the entire catalog.
For sure I will be able to keep a copy that will allow me to apply filters and to sync it on demand (and/or on a regular base) but I don't like the idea of duplicating the catalog.

1 REPLY 1
Guru

Re: Is there a way to query products from the catalog applying filters?

@sberndt This can be done using the query API. You would need to make two calls to do it based on features, but depending on the size of your catalog, this is likely still preferable to querying the entire catalog.

 

1. You would use the query API to to a ZOQL query on the ProductFeature object to get the features you want to use to locate the products. From this query you would obtain a set of "ProductId" fields and store that

 

2. Use the set of ProductId fields to make a query for the Product object. In the WHERE clause of the ZOQL you can add up to 200 entries to avoid needing repeated calls (i.e. WHERE Id = id1 OR Id = id2 OR ....)

 

This will then return you the products that match your features. If you have more than 200 features, then you would need an additional product query for each set of 200. (i.e. 375 features needs 2 Product queries, 410 features needs 3 product queries, and so on)