Magento 2 API: How do I list products as a customer or anonymous user

Magento 2 API: How do I list products as a customer or anonymous user

September 1, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 API: How do I list products as a customer or anonymous user

Magento 2 API: Listing Products for Customers and Guest Users

As a senior developer working extensively with e-commerce platforms like Magento 2, I often receive queries about accessing product information through the REST API for non-admin users such as customers or guests. In this post, we’ll explore how to list products using the /V1/products endpoint while maintaining proper authorization.

Understanding the Authorization Issue

When you attempt to access category or product resources as an anonymous user or a regular customer, Magento enforces robust security checks. These checks prevent unauthorized access to sensitive data and ensure that only the necessary information is exposed through the API.

The error message you received:

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

indicates that your current user context does not have permission to view category information. By default, Magento restricts access to most catalog resources for non-admin users.

Using Guest Access for Anonymous Users

For anonymous (guest) users who haven’t created an account or logged in, the API provides limited functionality out-of-the-box. To list products without requiring authentication, you can utilize the guest resource with appropriate permissions.

First, ensure that your store’s API settings allow guest access:

  1. In the Magento admin panel, navigate to Stores > Settings > Configuration.
  2. Select the scope (e.g., Default Config) under Current Configuration Scope.
  3. Under Advanced > System > Guest Permissions, set “Allow Guests to View Products” and “Allow Guests to Apply Coupon Codes” to Yes.

With this configuration, anonymous users can access public product information through the API using a guest token obtained from the /V1/integration/admin/token endpoint with admin credentials. Here’s an example:

$adminToken = $this->apiClient->getAdminToken('username', 'password');
$this->apiClient->setAccessToken($adminToken);
$guestToken = $this->apiClient->call('POST', '/V1/integration/admin/token', [
    'username' => $username,
    'password' => $password
]);

$this->apiClient->setAccessToken($guestToken['result']['token']);

Listing Products for Authenticated Customers

For authenticated customers, Magento provides more extensive access to product information through the customer resource. To list products for a specific customer:

  1. Obtain an authentication token using the /V1/integration/customer/token endpoint with the customer’s credentials.
$customerToken = $this->apiClient->call('POST', '/V1/integration/customer/token', [
    'username' => $customerEmail,
    'password' => $customerPassword
]);
  1. Set the obtained token as the access token for subsequent API requests.
$this->apiClient->setAccessToken($customerToken['result']['token']);
  1. Use the /V1/products endpoint to retrieve product data based on your desired filters and parameters, such as category IDs or search queries:
$products = $this->apiClient->call('GET', '/V1/products');

Building a Custom Customer API

If you need more control over the product listing for anonymous users, consider building a custom REST API module within your Magento installation. This approach allows you to define specific resources and permissions tailored to your application’s requirements.

For a comprehensive guide on creating custom REST APIs in Magento 2, refer to our blog post at LaravelCompany.com.

Conclusion

Magento 2 provides robust security features that limit access to product and category information for non-admin users. While the default API configuration restricts most resources, you can utilize guest access or authenticated customer tokens to list products based on your specific use case.

By following the best practices outlined in this post, you can ensure proper authorization while providing a seamless shopping experience for your customers through your mobile application or custom web interface.

Don’t hesitate to explore our other Magento 2 development resources at LaravelCompany.com for more insights into API integration and e-commerce platform management.

Magento 2 Catalog Security API

Our network