WooCommerce REST API "woocommerce_rest_cannot_view "
Asked Answered
C

6

1

when i paste this link

http://localhost/wordpress/wp-json/wc/v2/products?consumer_key=ck_*******************&consumer_secret=cs_********************

it show for me this error message

{"code":"woocommerce_rest_cannot_view","message":"D\u00e9sol\u00e9, vous ne pouvez pas lister les ressources.","data":{"status":401}}

by the way the cosumers key & secret are correct

Cochrane answered 30/8, 2018 at 17:2 Comment(0)
A
1

Your connection must be throw https and add this lines to your woocommerce init :

{
....
      verifySsl: false,
      queryStringAuth: true
}

every post request require ssl

dublicate from this link Ionic 3 WP-REST API Post request 401 (unauthorized) error & WooCommerce REST API "woocommerce_rest_cannot_view "

Atabrine answered 3/9, 2018 at 21:24 Comment(2)
queryStringAuth: true was the solution for meKimberykimble
Sorry I have no idea about wordpress. I am unable to find woocommerce init. Any clue?Inoculum
E
1

Here are 2 possible solutions:

  1. Add the following variable in the index.php page of your WordPress installation (Worked for me on my localhost without having to restart the server):

$_SERVER['HTTPS'] = 'on'; //------> Add this line under the line that says: define( 'WP_USE_THEMES', true );

  1. Set the environment variable in the .htaccess file when using Apache:

SetEnv HTTPS on

Erosion answered 21/11, 2021 at 12:55 Comment(0)
S
0

401 is unauthorized error

if key and secret are correct, it could be todo with SSL

other people report similar problems

https://github.com/woocommerce/woocommerce/issues/19649

Scandium answered 30/8, 2018 at 18:15 Comment(0)
V
0

Problem solved by adding this line below to the end of .htaccess file

All you need to add this line to .htaccess , this work with me

SetEnv HTTPS on

And make sure use OAuth 1.0 for Authorization

enter image description here

Verbena answered 10/4, 2021 at 13:59 Comment(0)
S
0

add false in end of creating RestAPI like this...

RestAPI rest = new RestAPI(URL, ConsumerKey, ConsumerSecret, false);

it should by "authorizedHeader"

answer from https://github.com/XiaoFaye/WooCommerce.NET/issues/211

Stratagem answered 8/2, 2022 at 7:26 Comment(0)
T
0

None of the suggestions helped me, so I deleted my previous API credentials and created new ones. This made the change for me.

I don't want to say "just delete your credentials" as you have to make sure to not break any necessary connections, please note that! I'm just sharing my experience on this.

Trass answered 30/9, 2022 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.