WooCommerce Rest API returns 404 not found

I am trying to get the number of products from WooCommerece using the REST API:

http://www.skyverge.com/woocommerce-rest-api-docs.html#authentication/over-https

I can visit this page and I get valid JSON:

https: // [omitted] .com / toilet-api / v1

When I visit / wc -api / v1 / products / count, I get 404 error:

{"errors": [{"code": "woocommerce_api_authentication_error", "message": "missing consumer key"}}}

Under "WooCommerce"> "Settings"> "Validation," secure validation is enabled. Is the code incorrect? It works great with the new 2.1 installation.

Here is my code:

public bool Authenticate() { try { HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(m_BaseUrl + "/products/count"); //myHttpWebRequest.Accept = "text/xml"; string userP = m_UserName + ":" + m_Password; byte[] authBytes = Encoding.UTF8.GetBytes(userP).ToArray(); myHttpWebRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(authBytes)); WebResponse httpResponse = myHttpWebRequest.GetResponse(); Stream responseStream = httpResponse.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); string resultData = reader.ReadToEnd(); responseStream.Close(); httpResponse.Close(); return true; } catch (Exception) { return false; } } GET https://www.[OMITTED].com/wc-api/v1/products/count HTTP/1.1 Authorization: Basic [OMITTED] Host [OMITTED] Connection: Keep-Alive 
+5
rest api php wordpress woocommerce
source share
1 answer

You need to include oauth_consumer_key in your request URL.

Log in to your WP-Admin and go to your user profile to generate API keys. You should see something with a consumer key and a consumer secret in the Woocommerce API Keys section.

After you get the value for the consumer key, your choice request will be:

http or https://yourdomain.com/wc-api/v2/products/?oauth_consumer_key=ck_670ae128f1ebb1859ba03b2171f8ca7c

Hope this helps

+1
source share

All Articles