magento get Catalog Price Rule or Discount Amount programmatically in the front-end by Rule Name

magento get Catalog Price Rule or Discount Amount programmatically in the front-end by Rule Name

July 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
magento get Catalog Price Rule or Discount Amount programmatically in the front-end by Rule Name

Getting Catalog Price Rule Discount Amount by Name in Magento Front-end

In Magento e-commerce, catalog price rules are used to apply discounts on selected products or categories. To get the discount amount of a specific rule programmatically from the front-end, you can use the Magento REST API.

Accessing Catalog Price Rules via REST API

The Magento REST API allows you to perform various operations, including retrieving catalog price rules. To access these rules, you’ll need to have an admin user with sufficient privileges and generate an integration token.

Step 1: Generate Integration Token

Log in as an administrator and navigate to Stores > Configuration > Advanced > System. Under the Integration tab, click on New Token.

Enter a label for your token and select the appropriate scope. Click Create Token. Save the generated token securely; you’ll need it later.

Step 2: Construct the API Endpoint

The REST API endpoint for catalog price rules is:

<magento_base_url>/rest/V1/catalogrule

Replace <magento_base_url> with your Magento installation’s base URL. For example, if your site is at https://example.com, the endpoint would be https://example.com/rest/V1/catalogrule.

Step 3: Call the API from Front-end

To call the API from the front-end, you can use JavaScript or a library like jQuery to make an HTTP request. Here’s an example using Fetch API:

const token = 'YOUR_INTEGRATION_TOKEN'; // Replace with your actual token
const ruleName = 'Your Rule Name';
const url = `https://example.com/rest/V1/catalogrule?searchCriteria[filter_groups][0][filters][0][field]=name&searchCriteria[filter_groups][0][filters][0][value]=${encodeURIComponent(ruleName)}`;

fetch(url, {
  method: 'GET',
  headers: {
    Authorization: `Bearer ${token}`,
    'Content-Type': 'application/json'
  }
})
.then(response => response.json())
.then(data => console.log(data.items[0].discount_amount))
.catch(error => console.error('Error:', error));

Replace 'Your Rule Name' with the name of the rule you want to retrieve. The function searches for a rule by name and logs its discount amount.

Best Practices

  • Always use HTTPS when making API calls to ensure data security.
  • Store integration tokens securely and restrict access to them. Never expose tokens in client-side code or version control systems.
  • Handle API errors gracefully in your front-end code.

Remember that using the REST API requires a stable internet connection, and API responses may take some time depending on your server’s performance and network conditions.

Conclusion

Retrieving catalog price rules programmatically from the Magento front-end is achievable through the use of the Magento REST API. By following best practices for generating integration tokens and constructing API requests securely, you can successfully access pricing data to enhance your site’s functionality.

For more detailed information on Magento development techniques, be sure to check out our blog archive at Laravel Company. We regularly publish insights on Magento e-commerce development, optimization, and best practices.

Catalog Database API Admin

Our network