Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I found difficulty in fetching a product from my woocommerce website to my django app based on the sku.

In the official documentation here: http://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-a-product

i found a solution only for fetching the product knowing the post id(794 in the example),like:

print(wcapi.get("products/794").json())

Is there a way to catch the product based on the sku?

like image 687
gtopal Avatar asked Jul 11 '19 07:07

gtopal


2 Answers

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']
like image 71
Mr. T Avatar answered Oct 17 '22 02:10

Mr. T


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.

like image 3
Esteban Salpeter Avatar answered Oct 17 '22 02:10

Esteban Salpeter