How to fetch a product from woocommerce api based on the sku? How to fetch a product from woocommerce api based on the sku? wordpress wordpress

How to fetch a product from woocommerce api based on the sku?


This also works as filter has been deprecated in newer versions:

sku="YOUR SKU HERE"productlist=wcapi.get("products/?sku="+sku).json()productid=productlist[0]['id']


At least as of REST API v3 SKU is included in get(params) possible values, so

    r = wcapi.get("products", params={'sku':sku})

would be the preferred method.


Finally found the answer.

r=wcapi.get("products?filter[sku]='"+sku+"'").json()