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":"[email protected]", "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.
3 Answers 3
I tried the below two options in different M2 versions:
- After login in Customer Account, tried to access
http://<hostname>/rest/V1/customers/me
Rest API with session based access. - Using Customer token tried to access
V1/customers/me
Rest API using Advanced Rest Client
In 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.
-
1I was able to get it working with new a installation. Really strange, didn't do nothing different than before with version 2.2.2.MePo– MePo2018年02月05日 08:31:36 +00:00Commented Feb 5, 2018 at 8:31
-
can you give me details on your server configuration (Php version, Database...). So i can compare to mine, i am wondering why it is working now (since i have no clue to why it is working now on version 2.2.2 )?MePo– MePo2018年02月05日 13:21:35 +00:00Commented Feb 5, 2018 at 13:21
I was having the same issue and finally found the solution here.
Turns out the issue was Postman - I had to delete the cookies that Postman automatically attaches to requests. Once I deleted all cookies for my site I was good to go.
the admin token is not required. The route rest/V1/customers/me
can be used by a logged in user without a token to return information about that customer. Please try the following:
- Go to storefront in browser
- Create user account
- Login to user account
- Enter URL
http://<hostname>/rest/V1/customers/me
, replacing with the server you are using
This will return information about the logged in customer directly to your browser.
If you want to get information about any other customer, you will need to generate an admin token and use it with the route GET /V1/customers/{customerId}
EDIT:
Have You tried this: CLICK HERE ?
It should be helpful :)
-
I tried exactly this before and i was getting the same error in browser. So there must be an error somewhere else?MePo– MePo2018年02月01日 14:11:06 +00:00Commented Feb 1, 2018 at 14:11
-
I just edit my postKonrad Siamro– Konrad Siamro2018年02月01日 15:09:37 +00:00Commented Feb 1, 2018 at 15:09
-
I will be building an mobile app, so that is the reason i chose this way. I will try this too. Just to see if i can get the user info and not the errorMePo– MePo2018年02月02日 06:28:17 +00:00Commented Feb 2, 2018 at 6:28
-
I solved this by "reinstalling" magento, fresh install and now it worked. The funny part is i didn't do anything different than the first time.MePo– MePo2018年02月05日 13:23:12 +00:00Commented Feb 5, 2018 at 13:23
customers/me
. My mistake, sorry. I will post answer