I’m using Woocomerce for my wordpress shopping cart. I’m connect my Android App to my WordPress database through Woocommerce REST API. I need to get products by category on my App. There is no provision in the REST API to fetch product by category.
I tried by using the filter attribute:
https://example.com/wc-api/v1/products?filter[product_cat]=gedgets&consumer_key=ck_9354534x&consumer_secret=cs_dx7345345
This is return me all the products.
In this case you should use the filters…
however, It worked for me :
the 16 is a sample of category id…
According to the WooThemes/WooCommerce documentation you need to use
filters
, like you say, only you appear to have the filter name wrong.Try:
categories
is the name of the field returned by the API, so that should be what you use.add key and use Consumer Key and Consumer Secret for type OAuth 1.0 authorization header and use this API.
http://yourdomain.com/wp-json/wc/v3/products/?category={ID}
I used this API and it’s perfectly working
Just in case anyone is trying to achieve this in the future with v2 of the Woo REST API, this is how it’s done:
https://${baseUrl}/wp-json/wc/v2/products?category=${categoryId}
And if you only have the slug of the category, as opposed to the id, you can first:
https://${baseUrl}/wp-json/wc/v2/products/categories?slug=${categorySlug}
use filter[category] insted of filter[categories]
if you are looking products filter by multiple categories id use below API endpoint:
Could it be a typo in your filtering?
I noticed that it says [categories]=gedgets but should it be [categories]=gadgets instead?
I am trying to figure out Woocommerce REST API myself and I noticed that if I type something wrong in the filter, it returns all results.
According to the Woocommerce REST API, They don’t have a solution(filters) for this issue. woocommerce github
Hope they will add this feture in their next release.
Actually, according to the github page, this feature is not yet available. However, if you look here: http://justgeeks.in/woocommerce-rest-api-fetch-products-category/ you will find what you need to filter by category slug…