node-wpapi: Error "rest_cannot_create", status 401
Hi,
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?
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 17
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.