• Resolved ggiggity

    (@ggiggity)


    HIi i’m building nextjs headless cms using wp and wc rest api

    currently hosting from aws lightsail we migrated from siteground. There was no problem with data fetching, everything was working until i tried to test out my headless cms.

    i hosted another website with same domain and there was a lot of conflicts, i deleted the new hosted website immediately.

    but ever since all the rest api data fetching returns 401 unauthorized “You can’t not list the resources”.

    none of the authorization methods works.

    const WooCommerceRestApi =require(“@woocommerce/woocommerce-rest-api”).default;

    export const api = new WooCommerceRestApi({

    url:process.env.DB_WEB,

    consumerKey: process.env.DB_KEY,

    consumerSecret: process.env.DB_TOKEN,

    version: “wc/v3”, });

    doesn’t work passing em to headers even basic auth doesn’t work with username and password.

    only some of them does work if i pass my consumer key and secret them into params I tried to fix it by making new website/ import back ups/ connect domain/ get fresh credentials, clear cache.i haven’t gotten any close to fixing it

    “code”: “woocommerce_rest_cannot_view”,

    “message”: “Sorry, you cannot list resources.”,

    “status”: 401

Viewing 1 replies (of 1 total)
  • Hi there @ggiggity, thank you for reaching out.

    A 401 error indicates that you’re dealing with an authorization issue. The fact that it started happening after you hosted another website with the same domain suggests that there might be some leftover conflicts or settings that are causing this issue.

    It is possible that the credentials you’ve supplied while trying to access the endpoint are wrong or invalid.

    The most common reasons for this are:

    • You have the wrong API keys (Consumer Key & Consumer Secret)
    • You have the wrong permissions set on the keys
    • The permalink settings for the site are incorrect

    I’d recommend taking a look at the WooCommerce REST API documentation here ad following the directions provided – https://woocommerce.com/document/woocommerce-rest-api/

    The documentation here goes over how to properly work with the API, how to test it, and also provides some tips for sorting out 401 errors – https://github.com/woocommerce/woocommerce/blob/trunk/docs/rest-api/getting-started.md

Viewing 1 replies (of 1 total)
  • The topic ‘Rest api auth error’ is closed to new replies.