WP-API / node-wpapi

An isomorphic JavaScript client for the WordPress REST API
http://wp-api.org/node-wpapi/
MIT License
1.68k stars 190 forks source link

Error code "rest_cannot_read", status code 401 #480

Open LeonardoCamargo31 opened 3 years ago

LeonardoCamargo31 commented 3 years ago

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

MartinSchere commented 3 years ago

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

LeonardoCamargo31 commented 3 years ago

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