Need to create rules based on bundles?
Learn more
LogoLogo
APIsChangelog
  • Getting started
  • Rules
  • Conditions
    • Scope
    • Aggregations
    • Nested
    • Dynamic values
  • Actions
    • Types
      • Percentage
      • Fixed amount
      • Fixed price
      • Buy X pay Y
      • Every X discount Y
    • Bundle
      • Balanced
      • Every
    • Aggregation
    • Limit
  • Matchers
  • Operators
  • Check and validation
  • Core API integration
    • Order rules
    • Price rules
    • Virtual relationships
  • Resources
    • Promotions
    • Price lists
  • Use cases
    • Promotions
      • Discount line items based on item's price
      • Get a discount when paying by credit card
      • Discount an order based on promo item and total number of items
      • Offer a specific shipping method for free in a specific country
      • Discount items with large stock availability
      • Discount all the SKU in an order based on the shipping country
      • Discount all the SKU in an order based on the customer email domain
    • Price lists
      • Discount all prices greater than or equal to a specific value
      • Discount specific SKUs for new clients
      • Change strike-through price based on customer email domain
On this page
  1. Core API integration

Price rules

How the Rules Engine integration with Commerce Layer Core API price lists resource works behind the scenes

PreviousOrder rulesNextVirtual relationships

Last updated 3 months ago

When you filling up the related rules object you're basically setting up price rules, meaning that the Core API integration will check your rules against the payload of a price. For performance reasons, it is a lightweight version of the , containing only the attributes and relationships needed to evaluate the rule and apply the related based on the values specified in the rule keys (e.g. fields, selectors, etc.).

Adding a price rule to a price list will result in applying the discounts due to the rule actions to all the price list's prices that satisfy the rule conditions.

The structure, constraints, and data types for the price rules JSON dataset are described in the public . Feel free to use it to implement validation scripts for your rules, automatically generate code, or just better understand how the Rules Engine works behind the scenes.

Example

The following rule offers a 20% discount on the prices of some promotional products (identified by a prefix in their SKU code) for the price lists associated with specific markets:

{
  "rules": [
    {
      "name": "20% discount off promo products in EU and AU markets",
      "conditions": [
        {
          "field": "price.sku.code",
          "matcher": "start_with",
          "value": "PROMO"
        },
        {
          "field": "price.jwt_markets.name",
          "matcher": "is_in",
          "value": ["Europe", "Australia"]
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "price",
          "value": "0.2"
        }
      ]
    }
  ]
}

The lightweight version of the price payload the rule is checked against by the Core API integration will contain only the strictly necessary information to evaluate the rule matching:

  • The SKU associated with the price and its code

  • The market associated with the JWT and its name

{
  "price": {
    "id": "lpeNYUvMTE",
    "sku": {
      "id": "klzEhmRAMM",
      "code": "PROMOTSHIRT"
    },
    "jwt_markets": [
      {
        "id": "jugEskRJSa",
        "name": "Europe"
      }
    ]
  }
}
create or patch a price list
conditions
actions
Price Rules JSON schema
full price payload