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):

curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/price_lists/vLrWRCDzBE/prices?fields[prices]=amount_cents,original_amount_cents,compare_at_amount_cents,processed_at' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token'

Checking a single price

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

curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/prices/aGqWUrMGEA' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token'

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

curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/prices/pVOMUMyNvA' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token'

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