8

I'm working on WooCommerce API, but I have problem with request.

Sometimes the API request return 404 or redirect to "my-account".

API request example :

https://example.com/index.php/wc-api/v3/products?consumer_key=ck_XXXXXXXXX&consumer_secret=cs_XXXXXXXXX`.

Pretty links are enabled.

Here is my .htacess

# BEGIN WordPress
 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
 </IfModule>
# END WordPress

Any ideas ?

user1269586
  • 372
  • 1
  • 6
  • 27
  • Have you tried all these: http://stackoverflow.com/questions/22429771/woocommerce-rest-api-returns-404-not-found https://github.com/kloon/WooCommerce-REST-API-Client-Library/issues/11 http://stackoverflow.com/questions/22710078/woocommerce-rest-api-404-error http://woopos.com.au/faq/getting-404-error-page-found/ – Tinh Dang May 03 '16 at 09:45
  • Yes I've try everything. Nothing work, I have permalink enabled – user1269586 May 03 '16 at 10:08
  • There's a space in the URI, I hope that's only a mistake in this question, not in your code: `consumer_secret= cs_XXXXXXXXX` – tillz May 08 '16 at 21:38
  • Where do you see a space ? There's no space – user1269586 May 08 '16 at 22:41
  • There's a space between "_secret=" and "cs_XX". If the request is going just like this, a %20 will be appended in cs_XX. I hope this isn't a problem. – Ankur May 09 '16 at 08:45
  • 1
    `Sometimes` is very well detailed explanation under what circumstances 404 occurs. You should add more details to your question. Does it mean, that you are able to get expected response from time to time with the same key and secret??? –  May 09 '16 at 08:46
  • edited. it was an error of typo but it is not the problem – user1269586 May 09 '16 at 08:47
  • I am too face this problem, and develop a plugin for this. I am using Woocommerce restapi library in this plugin. – er.irfankhan11 May 10 '16 at 06:34
  • Please provide your API code. The problem is either there or in your webserver configuration - for example if php on backend stopped answering. – Jehy May 10 '16 at 09:17

1 Answers1

1

Please download SDK from here: https://packagist.org/packages/automattic/woocommerce and take guidance from here: https://woothemes.github.io/woocommerce-rest-api-docs/. And create api credential form wordpress admin end woocommerce>settings>add new key

$client = 'ck_63aade4xxxxxxxxxxxxxxx'; //put client key
$secret = 'cs_673d7cdxxxxxxxxxxxxxxx'; //put secret key


require __DIR__ . '/restapi/vendor/autoload.php'; //give your sdk autoload.php path


use Automattic\WooCommerce\Client;

$woocommerce = new Client(
    'http://localhost:8888/woocommerce/', //site url
    $client, 
    $secret, // Your consumer secret
    [
        'version' => 'v3' // WooCommerce API version
    ]
);

print_r($woocommerce->get(''));
er.irfankhan11
  • 1,280
  • 2
  • 16
  • 29