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

3

6

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?

Kalahari answered 11/7, 2019 at 7:40 Comment(0)
K
0

Finally found the answer.

r=wcapi.get("products?filter[sku]='"+sku+"'").json()
Kalahari answered 11/7, 2019 at 7:59 Comment(0)
S
7

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']
Supplementary answered 2/12, 2019 at 14:46 Comment(0)
B
2

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.

Biotic answered 13/4, 2020 at 15:38 Comment(1)
K
0

Finally found the answer.

r=wcapi.get("products?filter[sku]='"+sku+"'").json()
Kalahari answered 11/7, 2019 at 7:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.