Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce API Return 404 Not Found

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 ?

like image 439
user1269586 Avatar asked Apr 28 '16 12:04

user1269586


1 Answers

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(''));
like image 165
er.irfankhan11 Avatar answered Nov 14 '22 23:11

er.irfankhan11