401 error
See original GitHub issueHi,
I’m testing the WP Node API and I’m trying to create a post, however I get this error:
{ "code": "rest_cannot_create", "message": "Sorry, you are not allowed to create new posts.", "data": { "status": 401 } }
I’m authenticating with my login for wordpress and testing it on localhost. This is the code:
var WPAPI = require( 'wpapi' );
var wp = new WPAPI({
endpoint: 'http://localhost/WordPressAPI/wordpress/wp-json',
username: 'username',
password: '--!',
auth: true
})
var post = wp.posts().create({
// "title" and "content" are the only required properties
title: 'Your Post Title',
content: 'Your post content',
// Post will be created as a draft by default if a specific "status"
// is not specified
status: 'publish'
}).then(function( response ) {
// "response" will hold all properties of your newly-created post,
// including the unique `id` the post was assigned on creation
console.log( response.id );
});
Running this code in NodeJS doesn’t do anything either. Does someone know what I’m doing wrong? Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
401 Unauthorized - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 401 Unauthorized response status code indicates that the client request has not been completed ...
Read more >How to Quickly Fix the 401 Unauthorized Error (5 Methods)
The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the ...
Read more >401 Error: 5 Ways to Troubleshoot and Fix It - Hostinger
The 401 Unauthorized error indicates that the server's request was not verified because it lacks valid authentication credentials for the target ...
Read more >How to Fix a 401 Unauthorized Error? - GeeksforGeeks
The 401 Unauthorized Error is an HTTP status code error that represented the request sent by the client to the server that lacks...
Read more >How to Fix a 401 Unauthorized Error - Lifewire
The 401 Unauthorized error is an HTTP status code that means the page you were trying to access cannot be loaded until you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @marcianosr and thanks for using the WordPress REST API (and this library!) May I ask whether you’re running the Basic Auth plugin on your site? That plugin must be installed and active for username/password authentication to succeed.
As a side note, the “auth: true” should be unnecessary, but would not contribute to the error you are seeing.
@marcianosr my pleasure, I’m glad to hear you got things working! Thanks for the update and let us know if you run into anything else!