1

I have integrated laravel 5.5 with magento 2.1

i-e: My magento installation works on http://magento.me and my laravel part works on http://magento.me/laravel-panel

When so ever my customer is logged in on magento site and i hit API /rest/V1/customers/me It returns me the customer data.

What could i do for getting admin data or know admin is logged via API . same customer/me API responded like wise when admin is logged in

{"message":"Consumer is not authorized to access %resources","parameters":{"resources":"self"}}

I have also applied admin authorization token with above request having admin level rights and All resources access.

1 Answer 1

1

You need to pass admin token in bearer. To get this token you need to consume below endpoint.

http://magento.me/rest/V1/integration/admin/token

and your request payload will look like below.

{
   "username" : "admin",
   "password" : "admin_password" 
}

You will get token in response just pass it authorization header like below.

$headers = array
   (
            'Authorization: Bearer=' . $token,
   );

Let me know if you need further help.

6
  • $userData = array("username" => "admin", "password" => "admin0101"); $ch = curl_init("http://ariaflex.me/rest/V1/integration/customer/token"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData)))); $token = json_decode(curl_exec($ch)); Magento is treating this account as customer instead of admin.
    – kazmi
    Commented Dec 17, 2018 at 11:59
  • sorry my mistake, It will be admin in url instead of customer. I updated my answer. Commented Dec 17, 2018 at 12:14
  • By adding this as an admin i can have access token. and passing that to customers/me it responded me with this response "message":"Consumer is not authorized to access %resources","parameters":{"resources":"self"}} Though my admin have all rights.
    – kazmi
    Commented Dec 17, 2018 at 12:19
  • for customer/me api you need to send customer token Commented Dec 17, 2018 at 12:32
  • Cant get admin data with your suggested solution .
    – kazmi
    Commented Dec 17, 2018 at 13:09

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.