Hi there
i was implementing an API Endpoint where i was querying the wixData . query ( “Stores/Products” ). This is by default limited to 50 items. I then overwritten it to 100 items which is the max according to API documentation.
now i’m getting 100 products, some of them are not in stock, some of them are. how can i get 100 products which are in stock only?
You have the DATABASE-FIELD → “inStock” in your DB.
Of which kind of type is it? —> STRING or BOOLEAN ?
Your code-(excerpt) seems to be ok.
$w.onReady(()=>{
wixData.query("Stores/Products")
.eq('inStock',true) //works on boolean field
//.eq('inStock',true) //works on string field
.limit(100)
.find()
.then((res)=>{
console.log(res);
}).catch((err)=>{console.log(err);});
});
According to the documentation, the “inStock” field cannot be filtered on.
" Description : Indicates whether the product is in stock. Type : Boolean Can connect to data : Yes Can use in dynamic page URL : No Can be sorted : No Can be filtered : No Read-only : Yes
"
That’s probably it. But i wonder why it’s not filterable… Doesn’t make sense to me.
I know, but the visability is not the problem, i want to return available-only products in my api endpoint. Since it’s limited I want to usefully use the capacity given.
If you are a mainstream-coder → your way end here.
If you are a genius custom-coder–> your adventures just starts here at this point.
Yes, you want to provide the filtered DATA to another SITE by generating an END-POINT. And yes you have a problem now.
But what about a WORKAROUND ?
What about just quering all data without filtration first.
And do the filterings by your own with your own generated CUSTOM-CODE ???
Be more flexible and use your fantasy + brain and you will get something like…
How to filter objects?
How to filter arrays including objects?
I don’t want to search the whole web for you to find something what will fit your needs, this will be your own task.
Start your coding-adventure right now and find your WORKAROUND to solve your problem.
When you have 150 products of which 95 are available and 55 aren’t. You’re wix query result set contains the first 100 rows ordered by created date descending (default). How do make sure, that you got all the 95 available products? filtering afterwards only filters those first 100 rows. So your solution solves problems, but not mine, mainstream coder
Yes, of course you are “geniously wondering” and you would do it THE NEXT 5-YEARS , if i wouldn’t be a nice person. Well everyone should get his second chance…
What you can do?
Do a normal query for 100-items.
Console-log the RESULTS you get.
Are you able to find “hasNext”.
If “hasNext” exists → than you can use a → “DO-WHILE-LOOP”…
…something like …