Error "rest_cannot_create", status 401
See original GitHub issueHi,
I’m making an app with React Native, and I use this module to handle WP API requests. I’m just messing around right now, but I keep having an error: “rest_cannot_create”, with status 401 and message saying that I don’t have permission to perform my request.
Here’s how I perform the basic auth:
const wp = new WPAPI({
endpoint: 'https://www.my-url.com/wp-json',
username: 'username',
password: 'passphrase',
auth: true
});
And my request looks like this:
wp.media()
.file( uri )
.create({
title: 'My awesome image',
alt_text: 'an image of something awesome',
caption: 'This is the caption text',
description: 'More explanatory information'
})
.then(function( response ) {
console.log(response);
var newImageId = response.id;
return wp.media().id( newImageId ).update({
post: userId
});
})
.then(function( response ) {
dispatch(setNewImageAvatar(response));
})
.catch(function( err ) {
console.log(err);
});
And well, I used the WP Basic Auth handler and enabled it: https://github.com/WP-API/Basic-Auth
What do I miss?
Issue Analytics
- State:
- Created 6 years ago
- Comments:14
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 >Error: Rest Cannot Create - WordPress.org
A 401 response status indicates that the client request has not been completed because it lacks valid authentication credentials for the requested resource....
Read more >401 Error - Rest Cannot Create · Issue #321 · WP-API/node ...
I have a locally hosted wp install with the auth plugin installed and am using a node script to interface with the site...
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 >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
I have the same issue , my code is as below . I get the
{ code: 'rest_cannot_create',message: 'Sorry, you are not allowed to create posts as this user.',data: { status: 401 } }
error. How can I resolve this, and is there any extra config needed on the WP dashboard side?If we introduce a generic way to modify outgoing requests (see #324) that will permit adding that query parameter without modifying the core library code. I will update this issue once we’ve implemented an option for that behavior.