admin管理员组

文章数量:1201785

I am using the postman for the check the REST API Call in WooCommerce. When I call the Woocommerce Defaults API. It displays the error like.

{
"code": "woocommerce_rest_cannot_create",
"message": "Sorry, you are not allowed to create resources.",
"data": {
    "status": 401
   }
}

The above error displays when the Basic Authentication and POST method of Create Customers API.

And when I am Trying to Call the Display products API with the cURL


Using the GET Methods from postman it will display the following error.

{
"code": "woocommerce_rest_cannot_view",
"message": "Sorry, you cannot list resources.",
"data": {
    "status": 401
   }
}

It would be great if anyone saving me from this headache. Thanks..

I am using the postman for the check the REST API Call in WooCommerce. When I call the Woocommerce Defaults API. It displays the error like.

{
"code": "woocommerce_rest_cannot_create",
"message": "Sorry, you are not allowed to create resources.",
"data": {
    "status": 401
   }
}

The above error displays when the Basic Authentication and POST method of Create Customers API.

And when I am Trying to Call the Display products API with the cURL

http://example.com/wp-json/wc/v2/products

Using the GET Methods from postman it will display the following error.

{
"code": "woocommerce_rest_cannot_view",
"message": "Sorry, you cannot list resources.",
"data": {
    "status": 401
   }
}

It would be great if anyone saving me from this headache. Thanks..

Share Improve this question asked Nov 6, 2017 at 6:12 Ajay GhaghretiyaAjay Ghaghretiya 1511 gold badge1 silver badge7 bronze badges 1
  • 1 Use https authentication in postman, instead of using oAuth1.0 as the authentication options. Use Basic authentication and pass consumer key as the username. And the password should be consumer secret. – LumberHack Commented Nov 6, 2017 at 11:55
Add a comment  | 

5 Answers 5

Reset to default 1

I got the solution for it. Use the Basic Authentication from the Postman.

Thanks

I also faced same issue, i tried in Postman, PHP, NodeJs everthing, almost spend 2 days but no output, finally started getting response after putting a slash at the end of the URL,

I mean,

Initially i was using https://example.com/wp-json/wc/v3/products?consumer_key=ck_XXXX&consumer_secret=cs_XXXX but change it to like this https://example.com/wp-json/wc/v3/products/?consumer_key=ck_XXXX&consumer_secret=cs_XXXX (Just put a slash before question mark in the start of query string).

In Postman even without set any Authorization settings(Type = No Auth), i started getting responses.

It may be somehow related to my .htaccess, but i feel it would good if i post this solution also here.

For me, it was an authentication issue.

I was using Basic auth for the postman

Just select OAuth 1.0 for authentication type and put the consumer and secret key on the field

Screenshot:

if you are using basic auth, be sure that apache is return header authorization, in you http.conf put this SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Make sure you have given Read/Write Access to the user and also check the .htaccess. Try to paste this code in your .htaccess and check again

# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<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

本文标签: phpProblem with Woocommerce REST API Authentication