> For the complete documentation index, see [llms.txt](https://docs.commercelayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.commercelayer.io/rules-engine/core-api-integration/order-rules.md).

# Order rules

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

When you [create a flex promotion](/rules-engine/resources/promotions.md) filling up the related `rules` object you're basically setting up **order rules**, meaning that the Core API integration will check your rules against the payload of an order. For performance reasons, it is a lightweight version of the [full order payload](/core-api-reference/orders/object.md), containing only the attributes and relationships needed to evaluate the rule [conditions](/rules-engine/conditions.md) and apply the related [actions](/rules-engine/actions.md) based on the values specified in the rule keys (e.g. fields, selectors, etc.).

{% hint style="info" %}
The resulting promotion (i.e. the rule actions) will be applied to all the orders that satisfy the rule conditions.
{% endhint %}

{% hint style="success" %}
The structure, constraints, and data types for the order rules JSON dataset are described in the public [Order Rules JSON schema](https://core.commercelayer.io/api/public/schemas/order_rules). 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.
{% endhint %}

## Example

{% tabs %}
{% tab title="Rules" %}
The following order rule offers free shipping and a 10% discount on the line items associated with an SKU if the email of the customer belongs to a specified domain:

<pre class="language-json"><code class="lang-json">{
  "rules": [
    {
      "name": "Get 10% off item cost plus free shipping for company customers",
      "conditions": [
        {
<strong>          "field": "order.customer_email",
</strong>          "matcher": "matches",
          "value": ".*@mybrand.com"
        }
      ],
      "actions": [
        {
          "type": "percentage",
<strong>          "selector": "order.line_items.sku",
</strong>          "value": "0.1"
        },
        {
          "type": "percentage",
<strong>          "selector": "order.line_items.shipment",
</strong>          "value": "1"
        }
      ]
    }
  ]
}
</code></pre>

{% endtab %}

{% tab title="Order" %}
The lightweight version of the order payload the rule is checked against by the Core API integration will contain only the strictly necessary information to evaluate the rule matching:

* The order's `customer_email`
* The order's line items of type `skus` and `shipments`

<pre class="language-json"><code class="lang-json">{
  "order": {
    "id": "oXkhYLlzgE",
<strong>    "customer_email": "john@mybrand.com",
</strong><strong>    "line_items": [
</strong>      {
        "id": "dKdhYLlzgE",
        "quantity": 1,
<strong>        "sku": { "id": "dKfhgdlzgE" }
</strong>      },
      {
        "id": "eKfhYFkztQ",
        "quantity": 2,
<strong>        "sku": { "id": "sDfhYFkcfR" }
</strong>      },
      {
        "id": "kKffYAkzdW",
        "quantity": 2,
<strong>        "sku": { "id": "sWfhYDccwQ" }
</strong>      },
      {
        "id": "adfSYwAzar",
        "quantity": 1,
<strong>        "shipment": { "id": "dwFhYDGtwE" }
</strong>      }
    ]
  }

</code></pre>

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.commercelayer.io/rules-engine/core-api-integration/order-rules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
