node-wpapi icon indicating copy to clipboard operation
node-wpapi copied to clipboard

Error code "rest_cannot_read", status code 401

Open LeonardoCamargo31 opened this issue 4 years ago • 2 comments

Hi,

I'm getting an error when trying to retrieve revisions to a post

Here's how I perform the basic auth:

const wp = new WPAPI({
   endpoint: 'https://www.my-url.com/wp-json',
   username: 'username',
   password: 'password',
   auth: true,
})

And my request looks like this:

wp
  .posts()
  .id(postId)
  .revisions()
  .then((result) => {
     console.log ('result', result)
     return result
   })

Error

{ 
  code: 'rest_cannot_read',
  message: 'No permission to view revisions to this post.'
  data: {status: 401}
}

In wordpress I'm using this plugin https://github.com/WP-API/Basic-Auth

Reference http://wp-api.org/node-wpapi/authentication/#basic-authentication

Am I doing something wrong? Can someone help me please

LeonardoCamargo31 avatar Feb 19 '21 21:02 LeonardoCamargo31

Have you checked your permissions to view posts? Is this your post?

MartinSchere avatar Feb 20 '21 01:02 MartinSchere

@MartinSchere I have the role as administrator, I can see the post, but this post is not mine.

LeonardoCamargo31 avatar Feb 22 '21 13:02 LeonardoCamargo31