# Price lists

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](https://docs.commercelayer.io/rules-engine/core-api-integration/price-rules).&#x20;

To make the Rule Engine work in conjunction with [price lists](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/price_lists), you need to do is [create](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/price_lists/create) a new (or [update](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/price_lists/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%:

<pre class="language-sh"><code class="lang-sh">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": {
<strong>        "rules": {
</strong><strong>          "rules": [
</strong><strong>            {
</strong><strong>              "name": "10% Discount on price greater than 10000 cents",
</strong><strong>              "conditions": [
</strong><strong>                {
</strong><strong>                  "field": "price.amount_cents",
</strong><strong>                  "matcher": "gt",
</strong><strong>                  "value": 10000
</strong><strong>                }
</strong><strong>              ],
</strong><strong>              "actions": [
</strong><strong>                {
</strong><strong>                  "type": "percentage",
</strong><strong>                  "selector": "price"
</strong><strong>                  "value": 0.1
</strong><strong>                }
</strong><strong>              ]
</strong><strong>            }
</strong><strong>          ]
</strong><strong>        }
</strong>      }
    }
  }
</code></pre>

## Available actions

The following [action types](https://docs.commercelayer.io/rules-engine/actions/types) are enabled on the flex promotions endpoint:

{% content-ref url="../actions/types/percentage" %}
[percentage](https://docs.commercelayer.io/rules-engine/actions/types/percentage)
{% endcontent-ref %}

{% content-ref url="../actions/types/fixed-price" %}
[fixed-price](https://docs.commercelayer.io/rules-engine/actions/types/fixed-price)
{% endcontent-ref %}

{% content-ref url="../actions/types/fixed-amount" %}
[fixed-amount](https://docs.commercelayer.io/rules-engine/actions/types/fixed-amount)
{% endcontent-ref %}

## 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](#example), you can simply:

* [Fetch all the price list's prices](#checking-the-price-lists-prices) and verify that only the desired ones have been discounted.
* [Fetch a single price](#checking-a-single-price) that should have been discounted and check if it's been correctly updated. This way you can also have access to the detailed rules outcomes.

{% hint style="warning" %}
To see the matching prices' amounts updated in the response remember to use a token with the market to which the price list belongs to [in scope](https://app.gitbook.com/s/-LgByaSP8eKjad-MIuHE/authentication#authorization-scopes).
{% endhint %}

### Examples

#### Checking the price list's prices

{% tabs %}
{% tab title="Request" %}
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](https://app.gitbook.com/s/-LgByaSP8eKjad-MIuHE/sparse-fieldsets)):&#x20;

```sh
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'
```

{% endtab %}

{% tab title="Response" %}
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:

<pre class="language-json"><code class="lang-json">{
  "data": [
    {
      "id": "pVOMUMyNvA",
      "type": "prices",
      "links": { ... },
      "attributes": {
        "amount_cents": 2900,
        "original_amount_cents": 2900,
        "compare_at_amount_cents": 4000,
        "processed_at": "2025-01-17T22:00:15.193Z"
      },
      "meta": {
        "mode": "test",
        "organization_id": "YyrQYFmLRk",
        "trace_id": "bfb801b193b16ff40d17c4411e79f9729a55ed85a9d00dde9c822be72fce439d"
      }
    },
    {
      "id": "gLQzUrPnEa",
      "type": "prices",
      "links": { ... }, 
      "attributes": {
        "amount_cents": 2900,
        "original_amount_cents": 2900,
        "compare_at_amount_cents": 4000,
        "processed_at": "2025-01-17T22:00:15.195Z"
      },
      "meta": { ... }
    },
    {
<strong>      "id": "peNYUxwryA",
</strong>      "type": "prices",
      "links": { ... },
      "attributes": {      
<strong>        "amount_cents": 9180,
</strong><strong>        "original_amount_cents": 10200,
</strong><strong>        "compare_at_amount_cents": 12000,
</strong><strong>        "processed_at": "2025-01-17T22:00:15.197Z"
</strong>      },
      "meta": { ... }
    },
    {
<strong>      "id": "aGqWUrMGEA",
</strong>      "type": "prices",
      "links": { ... },
      "attributes": {
<strong>        "amount_cents": 11610,
</strong><strong>        "original_amount_cents": 12900,
</strong><strong>        "compare_at_amount_cents": 15000,
</strong><strong>        "processed_at": "2025-01-17T22:00:15.198Z"
</strong>      },
      "meta": { ... }
    },
    {
<strong>      "id": "gMJQUkdKja",
</strong>      "type": "prices",
      "links": { ... },
      "attributes": {
<strong>        "amount_cents": 9180,
</strong><strong>        "original_amount_cents": 10200,
</strong><strong>        "compare_at_amount_cents": 12000,
</strong><strong>        "processed_at": "2025-01-17T22:00:15.200Z"
</strong>      },
      "meta": { ... }
    },
    {
      "id": "glnlUqkBop",
      "type": "prices",
      "links": { ... },
      "attributes": {
        "amount_cents": 2100,
        "original_amount_cents": 2100,
        "compare_at_amount_cents": 3000,
        "processed_at": "2025-01-17T22:00:15.202Z"
      },
      "meta": { ... }
    },
    {
      "id": "ARXmUrVwWa",
      "type": "prices",
      "links": { ... },
      "attributes": {
        "amount_cents": 9000,
        "original_amount_cents": 9000,
        "compare_at_amount_cents": 11100,
        "processed_at": "2025-01-17T22:00:15.203Z"
      },
      "meta": { ... }
    },
    {
      "id": "grBlUMJKlg",
      "type": "prices",
      "links": { ... },
      "attributes": {
        "amount_cents": 900,
        "original_amount_cents": 900,
        "compare_at_amount_cents": 1500,
        "processed_at": "2025-01-17T22:00:15.205Z"
      },
      "meta": { ... }
    }
  ],
  "meta": {
    "record_count": 8,
    "page_count": 1
  },
  "links": {
    "first": "https://rules-engine.commercelayer.co/api/price_lists/vLrWRCDzBE/prices?fields[prices]=amount_cents,original_amount_cents,compare_at_amount_cents,processed_at?page[number]=1&#x26;page[size]=10",
    "last": "https://rules-engine.commercelayer.co/api/price_lists/vLrWRCDzBE/prices?fields[prices]=amount_cents,original_amount_cents,compare_at_amount_cents,processed_at?page[number]=1&#x26;page[size]=10"
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

#### Checking a single price

{% tabs %}
{% tab title="Request" %}
The following request retrieves the price identified by the ID `aGqWUrMGEA` (matching price):&#x20;

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

{% endtab %}

{% tab title="Response" %}
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](https://docs.commercelayer.io/rules-engine/core-api-integration/price-rules) that the Core API integration created to be checked against the rule's condition.

<pre class="language-json"><code class="lang-json">{
  "data": {
    "id": "aGqWUrMGEA",
    "type": "prices",
    "links": { ... },
    "attributes": {
      "currency_code": "USD",
      "sku_code": "BACKPACK818488000000XXXX",
<strong>      "amount_cents": 11610,
</strong><strong>      "amount_float": 116.10,
</strong><strong>      "formatted_amount": "$116.10",
</strong><strong>      "original_amount_cents": 12900,
</strong><strong>      "formatted_original_amount": "$129.00",
</strong>      "compare_at_amount_cents": 15000,
      "compare_at_amount_float": 150.0,
      "formatted_compare_at_amount": "$150.00",
      "processed_at": "2025-01-17T22:44:50.941Z",
      "created_at": "2025-01-17T11:47:36.784Z",
      "updated_at": "2025-01-17T21:59:29.079Z",
      "reference": null,
      "reference_origin": null,
      "rules": {
<strong>        "rules": [
</strong>          {
            "id": "8b0419e1-8647-19b1-150d-06e9e8f7c005",
            "name": "10% Discount on price greater than 10000 cents",
            "actions": [
              {
                "type": "percentage",
                "value": 0.1,
                "groups": [ "23c015c7-56c4-4a7b-8c8f-26c992c72d9e" ],
                "selector": "price"
              }
            ],
            "conditions": [
              {
                "field": "price.amount_cents",
                "group": "23c015c7-56c4-4a7b-8c8f-26c992c72d9e",
                "value": 10000,
                "matcher": "gt"
              }
            ]
          }
        ]
      },
<strong>      "rule_outcomes": [
</strong>        {
          "id": "8b0419e1-8647-19b1-150d-06e9e8f7c005",
          "name": "10% Discount on price greater than 10000 cents",
          "priority": 0,
<strong>          "match": true,
</strong>          "conditions_logic": "and",
          "conditions": [
            {
              "field": "price.amount_cents",
              "group": "23c015c7-56c4-4a7b-8c8f-26c992c72d9e",
              "value": 10000,
              "matcher": "gt",
<strong>              "match": true,
</strong><strong>              "matches": [ { "price": "aGqWUrMGEA" } ],
</strong>              "scope": "any"
            }
          ],
          "actions": [
            {
              "resources": [
                {
                  "resource_type": "prices",
<strong>                  "id": "aGqWUrMGEA",
</strong>                  "quantity": null,
<strong>                  "value": 0.1,
</strong><strong>                  "action_type": "percentage"
</strong>                }
              ]
           }
          ]
        }
      ],
<strong>      "resource_payload": {
</strong><strong>        "price": {
</strong><strong>          "id": "aGqWUrMGEA",
</strong><strong>          "amount_cents": 12900
</strong><strong>        }
</strong><strong>      },
</strong>      "jwt_custom_claim": null,
      "metadata": {}
    },
    "relationships": {
      "price_list": { ... },
      "sku": { ... },
      "price_tiers": { ... },
      "price_volume_tiers": { ... },
      "price_frequency_tiers": { ... },
      "attachments": { ... },
      "versions": { ... },
      "jwt_customer": { ... },
      "jwt_markets": { ... },
      "jwt_stock_locations": { ... }
    },
    "meta": { ... }
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Request" %}
The following request retrieves the price identified by the ID `pVOMUMyNvA` (non-matching price):&#x20;

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

{% endtab %}

{% tab title="Response" %}
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](https://docs.commercelayer.io/rules-engine/core-api-integration/price-rules) that the Core API integration created to be checked against the rule's condition.

<pre class="language-json"><code class="lang-json">{
  "data": {
    "id": "pVOMUMyNvA",
    "type": "prices",
    "links": { ... },
    "attributes": {
      "currency_code": "USD",
      "sku_code": "5PANECAP000000FFFFFFXXXX",
<strong>      "amount_cents": 2900,
</strong><strong>      "amount_float": 29.0,
</strong><strong>      "formatted_amount": "$29.00",
</strong><strong>      "original_amount_cents": 2900,
</strong><strong>      "formatted_original_amount": "$29.00",
</strong>      "compare_at_amount_cents": 4000,
      "compare_at_amount_float": 40.0,
      "formatted_compare_at_amount": "$40.00",
      "processed_at": "2025-01-17T23:05:37.532Z",
      "created_at": "2025-01-17T11:46:16.929Z",
      "updated_at": "2025-01-17T11:46:16.929Z",
      "reference": null,
      "reference_origin": null,
      "rules": {
<strong>        "rules": [
</strong>          {
            "id": "8b0419e1-8647-19b1-150d-06e9e8f7c005",
            "name": "10% Discount on price greater than 10000 cents",
            "actions": [
              {
                "type": "percentage",
                "value": 0.1,
                "groups": [ "23c015c7-56c4-4a7b-8c8f-26c992c72d9e" ],
                "selector": "price"
              }
            ],
            "conditions": [
              {
                "field": "price.amount_cents",
                "group": "23c015c7-56c4-4a7b-8c8f-26c992c72d9e",
                "value": 10000,
                "matcher": "gt"
              }
            ]
          }
        ]
      },
<strong>      "rule_outcomes": [
</strong>        {
          "id": "8b0419e1-8647-19b1-150d-06e9e8f7c005",
          "name": "10% Discount on price greater than 10000 cents",
          "priority": 0,
<strong>          "match": false,
</strong>          "conditions_logic": "and",
          "conditions": [
            {
              "field": "price.amount_cents",
              "group": "23c015c7-56c4-4a7b-8c8f-26c992c72d9e",
              "value": 10000,
              "matcher": "gt",
<strong>              "match": false,
</strong><strong>              "matches": [],
</strong>              "scope": "any"
            }
          ],
<strong>          "actions": []
</strong>           }
          ]
        }
      ],
<strong>      "resource_payload": {
</strong><strong>        "price": {
</strong><strong>          "id": "pVOMUMyNvA",
</strong><strong>          "amount_cents": 2900
</strong><strong>        }
</strong><strong>      },
</strong>      "jwt_custom_claim": null,
      "metadata": {}
    },
    "relationships": {
      "price_list": { ... },
      "sku": { ... },
      "price_tiers": { ... },
      "price_volume_tiers": { ... },
      "price_frequency_tiers": { ... },
      "attachments": { ... },
      "versions": { ... },
      "jwt_customer": { ... },
      "jwt_markets": { ... },
      "jwt_stock_locations": { ... }
    },
    "meta": { ... }
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

## Use cases

If you need to check more examples of price lists based on the Rule Engine, feel free to explore the [related section](https://docs.commercelayer.io/rules-engine/use-cases/price-lists) of this documentation:

{% content-ref url="../use-cases/price-lists" %}
[price-lists](https://docs.commercelayer.io/rules-engine/use-cases/price-lists)
{% endcontent-ref %}
