1

i was trying to get the user data with JWT auth in wordpress.

i was send in the postman get request to /wp-json/wp/v2/users/me with the token that i get from /wp-json/jwt-auth/v1/token.

but i get this error:

{
    "code": "rest_not_logged_in",
    "message": "you are not logged in",
    "data": {
        "status": 401
    }
}

can someone help please

1
  • That ought to work I think. How exactly did you send the token?
    – Rup
    Commented Dec 30, 2020 at 10:18

1 Answer 1

2

I was just doing this earlier, if you are trying to simply get user data from your wordpress website with Postman just simply do a request to: /wp-json/wp/v2/users/

or directly to your user number: /wp-json/wp/v2/users/User Number here

(you will need ACF to REST API plugin ) so you can see the endpoint acf field below author and template. If you use ACF

It seems that you are trying to get data securely or post data then I would recommend the following:

install: JWT Authentication for WP-API plugin then edit your .htaccess and add:

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

and also add the following to your wp-config.php

define('JWT_AUTH_SECRET_KEY', 'any-secret-code-you-want');
define('JWT_AUTH_CORS_ENABLE', true);

And finally you will need to send a POST request in Postman to: /wp-json/jwt-auth/v1/token with the Header:

Content-Type
application/json

and the body:

{
    "username": "WordPressUserName",
    "password": "WordPressPassword"
}

Now Copy the Token in your results and create a new POST in Postman and in the Headers add: Authorization

Bearer **InsertYourToken**

And now you should have access to easly GET and POST data from your wordpress website.

you can also follow the video tutorial if you still get stuck, starting form this time: https://youtu.be/fFNXWinbgro?t=300

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.