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
rest api php wordpress woocommerce
user1255637
source share