What I need is to get all product IDs
that are 'instock'
using python.
It looks like this:
wcapi.get('products', params={"per_page": 100, 'stock_status': 'instock', 'tag': '1111'}).json()
This code works, but have max limit 100 per_page
, I don’t understand how can I acquire rest of them (about 2k items in stock) and moreover this request returns all info about products, but I need only IDs
.
3
Answers
Following the docs, I see that you can pass a page parameter also.
That makes it pretty straightforward to iterate all pages:
Edit: Bear in mind that this is going to process per page (in this case 100) products per loop.
There can be several approaches for solving this problem
You can fetch all products in a single call or in multiple calls according to your use-case
for example, you want to fetch 2k records in a single call
But the above approach is not good enough as the number of products may vary from time to time, therefore limiting products to be fetched is not a good solution for the long run.
Hence the better solution is to fetch the product details by multiple calls
After fetching all the product list you can fetch the product_ids like
I used this approach because I have a large quantity of products and kept getting disconnected with a while loop.