Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't POST/PUT/DELETE any products into WooCommerce by REST API

I'm using Wordpress 4.7.1 with Woocommerce 2.6.13 plugin with enabled REST API. I was created user credentials from console plugin UI with read_write permissions.

Now I'm trying GET products using OAuth1: enter image description here service return 200 OK, credentials are right.

then I'm trying to DELETE some product: enter image description here or trying to create new product: enter image description here service return 401 Unauthorized.

Whats wrong?

UPD1: .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

# END WordPress
like image 638
Sergey Nikitin Avatar asked Jan 21 '17 11:01

Sergey Nikitin


1 Answers

This https://github.com/woocommerce/woocommerce/wiki/Getting-started-with-the-REST-API#server-does-not-support-postdeleteput do the trick for me.

Some times, Server does not support POST/DELETE/PUT Ideally, your server should be configured to accept these types of API request, but if not you can use the _method property.

See https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_method-or-x-http-method-override-header

Doing a POST request, and passing _method=PUT as a query parameter works for me.

like image 58
Santiago Battaglino Avatar answered Sep 21 '22 06:09

Santiago Battaglino