Moltin Node SDK, Filtering Products by Category

products

#1

I cannot seem to filter my products using the Moltin Node SDK
I would like to search products by Category, EG: Leather
i do not really want to be getting all products then filtering on my microservice.
Could someone give me an example of how i would do this?
Thanks


#2

@thomassmwatson Unfortunately it is not currently possible to filter products by relationship on V2 of the API. This is not a limitation of the SDK. The best way to achieve this would be to get the category in question, and include the related products in the payload.

With the category ID:

Moltin.Categories.Get(id).With(['products'])

Or alternatively with the name/slug:

Moltin.Categories.All().Filter(
  eq: {
    slug: 'category-slug'
  }
}).With(['products']);

The response payload will include a top level included object with a products array.

{
  "data": {
     // Your category record
  },
  "included": {
    "products": [
      // The related products
    ]
  }
}

Filtering by relationships is functionality that will we introduce further down the product roadmap.

Hope this helps! :upside_down_face: