when I do http://dayroomstay.com/wp-json/wp/v2/users
I get:
"code": "rest_user_cannot_view",
"message": "Sorry, you are not allowed to list users.",
"data": {
"status": 401
}
I am using Postman... please help
when I do http://dayroomstay.com/wp-json/wp/v2/users
I get:
"code": "rest_user_cannot_view",
"message": "Sorry, you are not allowed to list users.",
"data": {
"status": 401
}
I am using Postman... please help
Read the docs: you need to add a Header named X-WP-Nonce
to your requests to the API that require authentication, as you can see in the jQuery example.
However the catch is getting that nonce in the first place. WordPress inject that token itself in the post editing screens. Type wpApiSettings
in the developer console and you can get the nonce. You will need to send your wordpress_logged_in
cookie too, that can be retrieved from the request headers in the Network tab of your browser dev tools.
I'm sharing an example of how you put that headers in your Postman request:
However making it for an app that is not coupled to the WP backend itself can be cumbersome, that´s why there are other options, like Basic authentication that I´m not a big fan, and JWT authentication plugin. Both are linked in the documentation page that I linked.