TransWikia.com

Getting 401 unauthenticated error in WP Rest API revisions

WordPress Development Asked on November 6, 2021

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 } }

One Answer

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.

Answered by haxpanel on November 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP