Posted on

How do I consume the REST API in Magento 2, using AJAX with session-based authentication?

I am having issues successfully making an AJAX call to Magento 2 REST API endpoints, using session-based authentication.

When I run the following javascript, I always receive a 401 (Not Authorized) error.

I am logged into the admin area as a user with all ACL privileges.

Here is the code that I am using to test the API:

url: ‘/rest/V1/customers/1’,
type: ‘get’

From what I can tell, by reading the Magento 2 docs, session-based authentication for the admin area, should work.

Can someone please tell me if it’s possible to consume the API this way, and how to get it working correctly.


Leave a Reply

Your email address will not be published. Required fields are marked *