How to get distinct values of a field in strapi via REST API

Hi all,

I have some clothing product data in my Strapi and I want to create some dynamic filters in my frontend for them. I don’t want to hardcode my filters.
E.g. I don’t want to show filters for sizes S, M, L & XL if not everything in the XL size is in stock.

I am trying to find a way to get the distinct values of the field with the size information that are in stock in order to only show filters that will return products if clicked.

If I try /api/products?fields[0]=size I will of course get all sizes in the database as many times as they are in the database.

Of course I could keep distinct values in the frontend after the response from the server gets back and I know I can create a custom route just for that.

Before going custom is there any functionality already in Strapi to get the distinct values from the REST API, or going custom is my only option?

Thanks in advance!