I'm trying to post to a WordPress server on an AWS Lightsail instance using node-wpapi. However, the server returns a 401 error.
I already have a .htaccess
file with RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
to my .htaccess
file and I already use 'application passwords' plugin.
How can I use node-wpapi to access the server?
My node-wpapi setting is here.
const wp = new WPAPI({
endpoint: 'http://localhost/wp-json',
username: 'user', //This is a default admin user.
password: '*************************', //This is a password for application passwords plugin
auth: true,
});
My .htaccess
file is here.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The error message is here.
code: 'rest_cannot_create',
message: 'Sorry, you are not allowed to create new posts.',
data: { status: 401 }
My user profile page keeps displaying the following message.
> Due to a potential server misconfiguration, it seems that HTTP Basic Authorization may not work for the REST API on this site: `Authorization` headers are not being sent to WordPress by the webserver. You can learn more about this problem, and a possible solution, on our GitHub Wiki.