Title: Authentication error with REST API
Last modified: August 31, 2016

---

# Authentication error with REST API

 *  Resolved [JCLondon](https://wordpress.org/support/users/jclondon/)
 * (@jclondon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/authentication-error-with-rest-api-1/)
 * Hi,
 * I have a WooCommerce website and I am building an app for it (HTML, ANGULARJS).
   I need to get the products from the website to show them into the app and I am
   using the REST API.
 * To get the products from WooCommerce I am using the WooCommerce REST API PHP 
   Client Library and I manage to get the products appear on screen via echo jsonencode.
 * I need to get the products via the URL but when I go to [http://example.com/wc-api/v3/products](http://example.com/wc-api/v3/products)
   I get the error
 * `{"errors":[{"code":"woocommerce_api_authentication_error","message":"oauth_consumer_key
   parameter is missing"}]}`
 * What have I missed? How do I obtain the oauth consumer key and where do I add
   it?
 * Thanks
    Jeff
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Contributor [Claudio Sanches](https://wordpress.org/support/users/claudiosanches/)
 * (@claudiosanches)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/authentication-error-with-rest-api-1/#post-7057979)
 * Just follow the docs: [https://packagist.org/packages/automattic/woocommerce](https://packagist.org/packages/automattic/woocommerce)
 * Example:
 *     ```
       <?php
       require __DIR__ . '/vendor/autoload.php';
   
       use Automattic\WooCommerce\Client;
       use Automattic\WooCommerce\HttpClient\HttpClientException;
   
       $url            = 'http://example.com';
       $consumerKey    = 'ck_xxxxxxxxxxxx'; // Change for your consumer key
       $consumerSecret = 'cs_xxxxxxxxxxxx'; // Change for your consumer secret
       $options        = [];
   
       $api = new Client($url, $consumerKey, $consumerSecret, $options);
   
       try {
       	$results = $woocommerce->get('products');
       	return json_encode($results);
       } catch (HttpClientException $e) {
       	return json_encode(['error' => ['code'=> [$e->getResponse()->getCode()], 'message'=> $e->getMessage()]]);
       }
       ```
   
 *  Thread Starter [JCLondon](https://wordpress.org/support/users/jclondon/)
 * (@jclondon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/authentication-error-with-rest-api-1/#post-7058068)
 * Hi Claudio, thank you so much for your reply, I have started from scratch again
   and followed the docs for what I can understand from it.
 * I have successfully installed the library via composer and I have created a file`
   products.php` in which I have added your code with the relative correct URL, 
   key and secret.
 * I have uploaded all the files in the root on the server and when I go to [http://example.com/products.php](http://example.com/products.php)
   I get a fatal error:
 * `Fatal error: Call to a member function get() on a non-object in /home/wardrob0/
   public_html/products.php on line 15`
 * on line 15 in products.php I have
 * `$results = $woocommerce->get('products');`
 * Is there anything wrong with that line? I can’t figure it out from the documentation.
 * Thank you
 *  Thread Starter [JCLondon](https://wordpress.org/support/users/jclondon/)
 * (@jclondon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/authentication-error-with-rest-api-1/#post-7058069)
 * Or should I put the files and folders somewhere else?
 * Thank you
 *  Thread Starter [JCLondon](https://wordpress.org/support/users/jclondon/)
 * (@jclondon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/authentication-error-with-rest-api-1/#post-7058078)
 * I have solved it, sorry. It was my bad I didn’t notice the different variables.
 * In case someone else needs this, the correct code is this
 *     ```
       <?php
       require __DIR__ . '/vendor/autoload.php';
   
       use Automattic\WooCommerce\Client;
       use Automattic\WooCommerce\HttpClient\HttpClientException;
   
       $url            = 'http://example.com';
       $consumerKey    = 'ck_xxxxxxxxxxxx'; // Change for your consumer key
       $consumerSecret = 'cs_xxxxxxxxxxxx'; // Change for your consumer secret
       $options        = [];
   
       $woocommerce = new Client($url, $consumerKey, $consumerSecret, $options);
   
       try {
       	$results = $woocommerce->get('products');
       	return json_encode($results);
       } catch (HttpClientException $e) {
       	return json_encode(['error' => ['code'=> [$e->getResponse()->getCode()], 'message'=> $e->getMessage()]]);
       }
       ```
   
 *  Thread Starter [JCLondon](https://wordpress.org/support/users/jclondon/)
 * (@jclondon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/authentication-error-with-rest-api-1/#post-7058079)
 * I have followed the docs but I do still get the same error.
 * I have uploaded all the files in the root on the server, is this the correct 
   place where I should put the files?
 * root
    – vendor – products.php (in this file I have added the example code you
   have sent me)
 * I need to get the products via the URL but when I go to [http://example.com/wc-api/v3/products](http://example.com/wc-api/v3/products)
   I get the error
 * {“errors”:[{“code”:”woocommerce_api_authentication_error”,”message”:”oauth_consumer_key
   parameter is missing”}]}
 * What am I doing wrong? Do I need to place the files somewhere else? Do I need
   to add something to the file products.php?
 * Many thanks
    Jeff
 *  [PKRulez](https://wordpress.org/support/users/pkrulez/)
 * (@pkrulez)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/authentication-error-with-rest-api-1/#post-7058096)
 * Hey,
 * Did you solve it?? Let me know also even i am confused where to upload the library
   files and setup.
 * Thanks,

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Authentication error with REST API’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [rest](https://wordpress.org/support/topic-tag/rest/)

 * 6 replies
 * 3 participants
 * Last reply from: [PKRulez](https://wordpress.org/support/users/pkrulez/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/authentication-error-with-rest-api-1/#post-7058096)
 * Status: resolved