> 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/core-api-reference/custom_promotion_rules.md).

# Custom promotion rules

The custom promotion rule object and the allowed CRUD operations on the related resource endpoint

Commerce Layer provides a promotional engine built on top of two main resources: [promotions](/core-api-reference/promotions.md) and [promotion rules](/core-api-reference/promotion_rules.md).

Custom promotions rules add extreme flexibility when building your promotion logic. They are used to trigger the associated promotion only when some specific conditions on the order attributes and/or relationships are met (e.g. the customer is tagged with a specific tag, the SKU code of the products in the cart contains a specific sequence of character, etc.). Those conditions are defined using the `filters` attribute:

```json
...
  "filters": {
    "{{predicate}}": {{value}},
    ...
  }
```

To compose the filter predicate you just need to follow the [same syntax](/core/filtering-data.md) you use when filtering a collection of resources — `{{attributes}}_{{matcher}}`. You must specify filtering rules as a valid JSON object. List values for the `*_in` matcher need to be expressed as arrays.

{% hint style="warning" %}
Since if you try to filter a collection of resources by a [non-filterable](/core/filtering-data.md#filterable-fields) or wrong/mispelled field you don't get any error and the API returns the full unfiltered list, make sure to use filters correctly (you can test them before via API). Otherwise, it would be like using no promotion rule and the promotion would be applied to [all the orders in scope](/core-api-reference/promotions.md#application-scope). The same happens if you create a custom promotion rule with no `filters` attribute.
{% endhint %}


---

# 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/core-api-reference/custom_promotion_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.
