Sylius API: How to implement "Find products by attribute value"

Hi Sylius people!

I would like to get products by attribute values via the API. The current Sylius APIv2 (https://master.demo.sylius.com/api/v2/docs) supports only the retrieval of products by name or taxons. What would be the recommended approach to implement this?

I see currently 2 possible solution proposals:

  • Writing a custom endpoint and querying the database and output some json
  • Extend the API-Platform Product resource and adding some attribute filter

What would be your approach?

I have used now the first approach by extending the API using a custom API filter, check details here: https://api-platform.com/docs/v2.7/core/filters/ (also make sure using the correct API Platform doc version).

You need to copy the whole API resource config and add your custom API filter to the list of filters. Check also the Sylius docs here: https://docs.sylius.com/en/1.12/customization/api/adding_and_removing_endpoints.html