Nginx Wordpress issue with REST Api 401 - wordpress

I have migrated from shared LAMP hosting to VPS NGINX and faced an issue with wordpress REST Api, when I try to get /wp-json/wp/v2/posts/ it response with error:
{
"code": "rest_forbidden",
"message": "You are not currently logged in.",
"data": {
"status": 401
}
}
But when I request woocommerce REST Api it works fine.
On Apache server all works fine.
Permalinks are enabled.
Have tried to add rewrite rules
rewrite ^/wp-json/(.*?)$ /index.php?rest_route=/$1 last;
But it has no effect

Related

Unauthorized response for metaslider rest api request after installing because of Disable Rest Api plugin

I have a problem with requsting rest API endpoint via postman,
the request is:
http://localhost/word-test/wordpress/wp-json/metaslider/v1/slideshow/all
and response is:
{
"code": "rest_forbidden",
"message": "Sorry, you are not allowed to do that.",
"data": {
"status": 401
}
}
IF I requested:
http://localhost/word-test/wordpress/wp-json/wp/v2/posts/
Then everything works properly.
The problem was found after I installed https://wordpress.org/plugins/disable-json-api/ ... Things I've tried:
enable or disable metaslider links "wp-json/metaslider/v1/slideshow/all" in "Disable Rest API" plugin for authenticated and unauthenticated users.
Delete or deactive The whole plugin
Any clue, please?
Note: I am using localhost links here to explain my problem but I have the same issue in a real site

How to host static files of a single page webapp in firebase hosting, and deploy the web API in a different server

I have a single page webapp which uses a REST API exposed through the same domain. Currently, the static files are served by the same server which exposes the REST API.
I am trying to offload the static file serving to firebase hosting. If I move the static files to firebase hosting, I have to point the DNS entries of my domain to firebase hosting, which will make the webapp to issue REST requests to firebase hosting as well.
I can update the webapp so that it will issue the REST requests to the current server address instead of firebase hosting, but it will make the requests slow since browser will use preflight requests before issuing every request due to CORS.
Does anyone know how to properly resolve this?
This can be handled with Hosting Config, specifically using redirects you can reference location /foo as your static url path and have it load content from /bar
"hosting": {
// ...
// Returns a permanent redirect to "/bar" for requests to "/foo" (but not "/foo/**")
"redirects": [ {
"source": "/foo",
"destination": "/bar",
"type": 301
} ]
}
There are other options if you need to handle cloud functions using rewrites and more, I suspect a combination will suit your needs. Please check out the full example in the documentation for reference.
Update:
To setup an API route without cors - you can do the following
app.get("/apiPath", cors({origin: false}), (req, res) => {
/...
})

PageSpeed Insights times out

I have several websites hosted on the same provider. No matter what site I try, I get a "timed out" error on the Google PageSpeed Insights site (https://developers.google.com/speed/pagespeed/insights/) when I enter any of my site URLs. It doesn't matter how large or how small the website is.
What I do is this: I enter my site's URL into Google's Page Insights "Enter a web page URL" textbox and click, "Analyze." The status bar reaches about 81% before I get the following error:.
"Lighthouse returned error: FAILED_DOCUMENT_REQUEST. Lighthouse was unable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests. (Details: net::ERR_TIMED_OUT)"
When I look at Chrome's developer tools, it yields the following information about the script Google is using and where it is failing on their site:
PageSpeed 500 error
If I drill down to the URL of the API being used on Google's site, it is calling the runPagespeed method and returning a 403 error:
/*
{
"error": {
"code": 403,
"message": "Requests from referer \u003cempty\u003e are blocked.",
"errors": [{
"message": "Requests from referer \u003cempty\u003e are blocked.",
"domain": "global",
"reason": "forbidden"
}],
"status": "PERMISSION_DENIED"
}
}
*/
I'm lost as to why Google is returning a 403 error. I see nothing on my site's logs that indicates it's hitting a 403 error, so I can only assume the 403 error is on Google's end, or Lighthouse. Thanks in advance for any help or suggestions.

Post with REST API on Wordpress.com [Error 401, not allowed]

I want to post articles with rest on one of my wordpress.com websites (wordpress website hosted on the free wordpress.com platform).
Endpoint, GET on: https://public-api.wordpress.com/wp/v2/sites/donnadulcinea.wordpress.com/posts
With Basic-Auth header. Body of the request (for test),
{"title":"New Rest Post"}
Response:
{
"code": "rest_cannot_create",
"message": "Sorry, you are not allowed to create posts as this user.",
"data": {
"status": 401
}
}
What's wrong? Where may I found one final example for a really simple posting on a wordpress.com domain?
First, are you using the basic auth plugin? here
Second, I'm not sure if your endpoint is correct. This is how I use:
http://localhost/wp-json/wp/v2/posts
I tried in my website, with this json:
{
"title":"title",
"content":"content",
"categories":"news",
"status":"publish"
}
and it worked
I just faced the same issue. Download the miniOrange API Authentication plugin.
Then, if running on an Apache server, add the below two lines to your .htaccess file after the RewriteBase:
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
Works like a charm.

Google Translate API v2 403 error on server - not from 2 dev boxes

Using a Server API Key from 2 different dev boxes and Google Translate works fine. On the server I get the following error:
{
...
"code": 403,
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}
I have added the Server IP to the list of approved IPs. I have tried using a browser key as well to no avail.

Resources