Getting 401 unauthenticated error in WP Rest API revisions

I'm trying to fetch preview data through WP Rest API using a url such as /wp-json/wp/v2/pages/1140/revisions/1653.

An extra header is also included: 'X-WP-Nonce': nonce - nonce comes from WP.

Why am I getting 401 unauth error? Thanks

{ code: 'rest_cannot_read',
2020-07-21T11:45:35.930292+00:00 app[web.1]:   message: 'Sorry, you are not allowed to view revisions of this post.',
2020-07-21T11:45:35.930293+00:00 app[web.1]:   data: { status: 401 } }

Topic previews revisions rest-api Wordpress

Category Web


The solution was to generate and use an API token.

  1. in WP admin, go to user and generate the key
  2. take that key and glue it with the username it is generated with in this format: username:key
  3. base64 encode that string
  4. put that base64 value into the header: 'Authorization': 'Basic <base64 token here>'

In my case, the key was deleted.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.