13

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
Sergey Nikitin
  • 763
  • 7
  • 22
  • 1
    Hi Sergey, I suggest you paste the error text into the question rather than using screenshots. Easier to find on Google. – James Jones Jan 26 '17 at 01:29
  • Hi @JamesJones! Yhanks for you responce. Of course, I tryed to use find it on Google. Can you help me and give us WORKING solution? From Google, for example. – Sergey Nikitin Jan 27 '17 at 11:33
  • That's not what I mean exactly. I mean you should not use screenshots of errors. You should paste the text of the error into your question. This makes it easier for people to follow your question and easier for people with the same problem to find your question using Google. Which makes it more likely someone will answer your question. – James Jones Jan 27 '17 at 13:45
  • Possible duplicate of [Android-Cant create order using woocommerce api](http://stackoverflow.com/questions/43348471/android-cant-create-order-using-woocommerce-api) – debo.stackoverflow Apr 14 '17 at 13:18

4 Answers4

2

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.

1

You are using an old version API method. Use the latest version with the updated woocommerce plugin.You can also follow this link https://woocommerce.github.io/woocommerce-rest-api-docs/?php#delete-a-product

Aman Kumar
  • 123
  • 8
0

What are the roles of the user that is associated with the API keys?

I had some authorization errors with the Woocommerce API, even though the API keys had read/write permissions. After I checked the Woocommerce API keys settings in Wordpress, I noticed that the user that was associated with the keys I used, didn't have any Woocommerce roles, such as Customer, Shop Manager or Admin.

After associating an admin user to some new API keys, I resolved the issue and could authorise with all API endpoints.

Since you are authorised for only some of the endpoints, it could be the same issue. The user that is associated with the API keys probably doesn't have a role with permissions to delete.

piscator
  • 5,521
  • 3
  • 19
  • 29
0

I've had the same problem with WC REST API and solved it using v2 and instead of PUT I used POST, e.g.:

$woocommerce = new Client(
    '*** woocommerce-website-url ***',
    '*** key ***',
    '*** secret ***',
    [
        'version' => 'wc/v2',
        'verify_ssl' => false,
        'wp_api' => true,
        'query_string_auth' => true
    ]
);

$data = [
    "stock_quantity" => "0"
];

$woocommerce->post('products/12345', $data);
Ivan Velkov
  • 179
  • 1
  • 4