Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: "Request failed with status code 401" #8

Closed
Laurynas-Sirgedas opened this issue Sep 14, 2021 · 4 comments
Closed

error: "Request failed with status code 401" #8

Laurynas-Sirgedas opened this issue Sep 14, 2021 · 4 comments
Assignees
Labels

Comments

@Laurynas-Sirgedas
Copy link

When I was trying to reach http://localhost:3000/api/get-products I get an error
{ success: false, products: [ ], error: "Request failed with status code 401", }

@Laurynas-Sirgedas
Copy link
Author

An issue occurred because I've followed all instructions and set the WordPress site address to http://localhost:3000
When I set the Site address (frontend) to a normal domain (the same as WordPress Address) address, then the issue disappears

@GPorter43
Copy link

Is there a more elegant solution to this as using the normal WordPress address will cause the permalinks to link to the wordpress site not the headless Nextjs site

@imranhsayed
Copy link
Owner

imranhsayed commented Oct 2, 2021

@Laurynas-Sirgedas , @GPorter43

  • Thanks for bringing this up 👍
  • When we set site address url to frontend url, by default wp rest endpoint gets that frontend url as base point.
  • So an actual backend url required an update for REST api only. I have made the changes to the Headlesss CMS Plugin

So this is resolved, Please pull the latest changes from https://github.com/imranhsayed/headless-cms or download the latest version of the plugin.
Now you should be able to set the SITE URL to the front end url from WordPress General Settings
image

image

@imranhsayed imranhsayed self-assigned this Oct 2, 2021
@renjogabro
Copy link

renjogabro commented Nov 19, 2022

@Laurynas-Sirgedas , @GPorter43

  • Thanks for bringing this up 👍
  • When we set site address url to frontend url, by default wp rest endpoint gets that frontend url as base point.
  • So an actual backend url required an update for REST api only. I have made the changes to the Headlesss CMS Plugin

So this is resolved, Please pull the latest changes from https://github.com/imranhsayed/headless-cms or download the latest version of the plugin. Now you should be able to set the SITE URL to the front end url from WordPress General Settings image

image

@imranhsayed,
Many thanks for the wonderful work.
However, this is not resolved for me, even though I have the latest version of HCMS. When I set site to localhost:3000 in Wordpress General settings, I get the same result of

{ success: false, products: [ ], error: "Request failed with status code 401", }
when I try to reach: http://localhost:3000/api/get-products

It was the same for trying to use function getStaticProps() with this endpoint: /wp-json/rae/v1/header-footer?header_location_id=hcms-menu-header&footer_location_id=hcms-menu-footer.
However, this particular problem was solved by adding "index.php" in url, like so:

/index.php/wp-json/rae/v1/header-footer?header_location_id=hcms-menu-header&footer_location_id=hcms-menu-footer

But still not elegant, and would be perfect if this was resolved with the Wordpress General settings.

Any chance you could look into this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants