1

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.

  • Are you sure that user have role with access to this resource?? – Konrad Siamro Feb 1 '18 at 13:47
  • I created this customer and i am using his data to get customer token ( If i figured out correctly ) then to get his data. I didn't add / change any roles, as i taught it was not necessary ( Since documentations didn't mention to do that for Customer access tokens, only for Integration token type) – MePo Feb 1 '18 at 13:56
  • ahh didnt notice there is customers/me . My mistake, sorry. I will post answer – Konrad Siamro Feb 1 '18 at 14:05
  • What is your exact Magento 2 version? – PY Yick Feb 2 '18 at 2:47
  • My version is 2.2.2 – MePo Feb 2 '18 at 6:24
1

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.

|improve this answer|||||
  • 1
    I 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 Feb 5 '18 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 Feb 5 '18 at 13:21
0

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 :)

|improve this answer|||||
  • I tried exactly this before and i was getting the same error in browser. So there must be an error somewhere else? – MePo Feb 1 '18 at 14:11
  • I just edit my post – Konrad Siamro Feb 1 '18 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 error – MePo Feb 2 '18 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 Feb 5 '18 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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