I am bulding a mobile app and I know there are a lot of these questions and I went trough them all, but i still got this problem (Using Magento 2.2.2). I tried with curl, postman, hurl.it and i get this message
message : "Consumer is not authorized to access %resources" parameters
: {resources: "self"}
This is my request (Postman)
GET /rest/V1/customers/me HTTP/1.1
Host: myshop.dev
Authorization: Bearer grw5y9b3se261541evcdl1js8jd27c8f
Cache-Control: no-cache
What i did so far:
- I did put space on
Bearer grw5y9b3se261541evcdl1js8jd27c8f
- Checked everything multiple times (letter by letter)
Further explanation:
This is a new installation of Magento with sample data.
I have read the documentation here http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-token.html , and i am doing it using Customer access tokens. (Since i am doing a mobile app i chose this way) I also registered/created a customer and with his email / password i am doing the following:
(Curl example)
curl -X POST "http://myshop.dev/rest/V1/integration/customer/token"
-H "Content-Type:application/json"
-d "{"username":"customer1@example.com", "password":"customer1pw"}"
and that returns me token, with it i am trying to do a request (see Postman request) to see user data, but with no success. Am i missing something here? Something in apache, php? or am i doing something wrong.
EDIT
Since nothing worked I deleted Magento and did a fresh installation again, and now it works, I didn't do anything different than before, and that is very confusing.
Best Answer
I tried the below two options in different M2 versions:
http://<hostname>/rest/V1/customers/me
Rest API with session based access.V1/customers/me
Rest API using Advanced Rest ClientIn Magento version 2.1.6 both above options worked fine.
In Magento version 2.2.2, I was getting
Consumer is not authorized
error in first option but able to get the customer info from second info.