• Resolved Jesin A

    (@jesin)


    I cannot get the Woocommerce REST API to work at all.

    I logged in as an administrator, created a pair of keys with read/write permission and opened the following URL:

    https://example.com/wp-json/wc/v2/payment_gateways?consumer_key=ck_abc&consumer_secret=cs_abc

    I got the following error:

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

    I opened the file that generated this error (woocommerce/packages/woocommerce-rest-api/src/Controllers/Version2/class-wc-rest-payment-gateways-v2-controller.php) and added the following on line 84 inside the get_items_permissions_check() function.

    var_dump( get_current_user_id() );

    To my surprise it returned 0 even though I was logged into WordPress.

    What is going on here?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @jesin!

    This is a common authentication issue — the response indicates you are not authorized for that REST endpoint

    Please review the documentation once more, from here: https://woocommerce.github.io/woocommerce-rest-api-docs/#authentication

    .. and ensure that if you are using Basic auth that https is used for connection and that the user creating the REST API keys have both read/write permissions.

    Cheers!

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Howdy!

    We haven’t heard back from you in a while, so I’m going to go ahead and mark this thread as resolved. If you have any other questions please start a new thread.

    Cheers!

    Thread Starter Jesin A

    (@jesin)

    Hey Rynaldos,

    I could never get this to work, as I said the get_current_user_id() function inside get_items_permissions_check() was returning 0.

    I’m using a different plugin which doesn’t need the Woocommerce REST API.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘woocommerce_rest_cannot_view error when using the REST API’ is closed to new replies.