For the complete documentation index, see llms.txt. This page is also available as Markdown.

Price lists

How to use the Rules Engine in conjunction with price lists and set up price rules

The Rule Engine enables you to manage discounts and more also a the price list level (e.g. changing the standard prices of a price list based on certain conditions), using the proper price rules.

To make the Rule Engine work in conjunction with price lists, you need to do is create a new (or update an existing) price list and specify the price rules that you want to be implemented in the rules object. The discount defined by the related actions will be automatically applied to the price list's prices that match the given conditions.

Example

The following request updates the price list identified by the ID vLrWRCDzBE so that all the prices with an amount greater than 10000 cents will be discounted by 10%:

curl -g -X PATCH \
  'https://yourdomain.commercelayer.io/api/price_lists/vLrWRCDzBE' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
    "data": {
      "type": "price_lists",
      "id": "vLrWRCDzBE",
      "attributes": {
        "rules": {
          "rules": [
            {
              "name": "10% Discount on price greater than 10000 cents",
              "conditions": [
                {
                  "field": "price.amount_cents",
                  "matcher": "gt",
                  "value": 10000
                }
              ],
              "actions": [
                {
                  "type": "percentage",
                  "selector": "price"
                  "value": 0.1
                }
              ]
            }
          ]
        }
      }
    }
  }

Available actions

The following action types are enabled on the flex promotions endpoint:

PercentageFixed priceFixed amount

Check and validation

Checking if a price rule has been correctly applied is pretty straightforward. Once you've applied the desired rules at the time of the price list's creation or update as shown in the example above, you can simply:

Examples

Checking the price list's prices

The following request retrieves all the prices belonging to the price list identified by the ID vLrWRCDzBE (for better readability we requested only a subset of fields):

On success, the API responds with a 200 OK status code, returning a paginated collection of price list's prices. As you can see the prices whose amount was greater than 10000 cents now show an amount_cents that differs from the original_amount_cents, being discounted by 10% as specified in the rule's action:

Checking a single price

The following request retrieves the price identified by the ID aGqWUrMGEA (matching price):

On success, the API responds with a 200 OK status code, returning the requested price object. Being the original amount of the price greater than 10000 cents, it has been discounted by 10%, as can be seen by comparing the amount_cents and the original_amount_cents values. For more information, you can inspect the rules object in the response:

  • The rules_outcomes object shows that the price matches the rule's condition and that the requested action has been applied.

  • The resource_payload object is the lightweight price payload that the Core API integration created to be checked against the rule's condition.

The following request retrieves the price identified by the ID pVOMUMyNvA (non-matching price):

On success, the API responds with a 200 OK status code, returning the requested price object. Being the original amount of the price lower than 10000 cents, it hasn't been discounted and the amount_cents value is still equal to the original_amount_cent value. For more information, you can inspect the rules object in the response::

  • The rules_outcomes show that the price doesn't match the rule's condition (the conditions.matches array is empty). Consequently, no action is applied (the actions array is empty as well).

  • The resource_payload is the lightweight price payload that the Core API integration created to be checked against the rule's condition.

Use cases

If you need to check more examples of price lists based on the Rule Engine, feel free to explore the related section of this documentation:

Price lists

Last updated