1

I'm trying to get details of specific users using Wordpress REST API. I'm sure that I use admin credential to get the details.

But I keep getting the following response,

{
    message: "Sorry, you’re not allowed to list users",
    code: "rest_user_cannot_view"
}

I double-checked the credentials are of admin's. And admin has access to get user details. Tried using this solution, https://stackoverflow.com/a/36499422 But it didn't work.

1 Answer 1

1

The answer you tried contains everything that you need.

But there is a bit of confusion going there. So I'm answering here again.

By default, Wordpress doesn't allow Basic Authentication. Read more about Basic Auth here https://en.wikipedia.org/wiki/Basic_access_authentication

So you need enable this by installing a plugin which enables Basic Auth.

Enabling that isn't enough. Your server may not listen for "Authorization" header. The header isn't getting passed to the rest api from the request.

You need to enable that by modifying .htaccess as mentioned in that answer. Like,

*# BEGIN WordPress*

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP:Authorization} ^(.*)

RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

</IfModule>

*# END WordPress*

You may already have RewriteEngine On, if so leave that line, include otherwise

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.