# Limit

You can impose additional restrictions to the number of items on which an action will be applied by specifying the `limit` object. This way, the action will be applied only to the number of items specified in the limit's `value` key, according to the sorting logic set in the limit's `sort` object (i.e. computed on the field of the action's selector defined in the `sort.attribute` key using the function indicated in the `sort.direction` key).

<table><thead><tr><th width="180">Key</th><th width="135">Type<select><option value="Djzo1UhBKQfW" label="Boolean" color="blue"></option><option value="VAIMp1rdLBI0" label="Integer" color="blue"></option><option value="qhaoRE82Rs3C" label="Float" color="blue"></option><option value="sk9tHN8WC8KO" label="String" color="blue"></option><option value="B3M67zaVXhvQ" label="Array" color="blue"></option><option value="MFocCrV7v0L6" label="Object" color="blue"></option></select></th><th width="114" data-type="checkbox">Required</th><th width="282">Description</th><th>Example</th></tr></thead><tbody><tr><td><strong><code>value</code></strong></td><td><span data-option="VAIMp1rdLBI0">Integer</span></td><td>true</td><td>The number of items on which to apply the action, according to the logic specified in the <code>sort</code> object.</td><td><code>2</code></td></tr><tr><td><strong><code>sort</code></strong></td><td><span data-option="MFocCrV7v0L6">Object</span></td><td>true</td><td>The sorting logic to apply before executing the limit.</td><td>Learn more <a href="#sort">here</a>.</td></tr></tbody></table>

## Sort

Use the `limit.sort` object to specify the desired sorting logic by setting the following keys:

<table><thead><tr><th width="192">Key</th><th width="145">Type<select><option value="Djzo1UhBKQfW" label="Boolean" color="blue"></option><option value="VAIMp1rdLBI0" label="Integer" color="blue"></option><option value="qhaoRE82Rs3C" label="Float" color="blue"></option><option value="sk9tHN8WC8KO" label="String" color="blue"></option><option value="B3M67zaVXhvQ" label="Array" color="blue"></option><option value="MFocCrV7v0L6" label="Object" color="blue"></option></select></th><th width="115" data-type="checkbox">Required</th><th width="268">Description</th><th>Example</th></tr></thead><tbody><tr><td><strong><code>attribute</code></strong></td><td><span data-option="sk9tHN8WC8KO">String</span></td><td>true</td><td>The field of the resource specified in the action's selector on which to apply the limit sorting. Works with numeric fields only.</td><td><code>"unit_amount_cents"</code></td></tr><tr><td><strong><code>direction</code></strong></td><td><span data-option="sk9tHN8WC8KO">String</span></td><td>true</td><td>The sorting function to be used. Can be one of <code>asc</code> or <code>desc</code>.</td><td><code>"asc"</code></td></tr></tbody></table>

{% hint style="info" %}
You can set a limit on [percentage](https://docs.commercelayer.io/rules-engine/actions/types/percentage), [fixed amount](https://docs.commercelayer.io/rules-engine/actions/types/fixed-amount), and [fixed price](https://docs.commercelayer.io/rules-engine/actions/types/fixed-price) actions only, provided that you're not using [bundles](https://docs.commercelayer.io/rules-engine/actions/bundle).&#x20;
{% endhint %}

## Example

The following action applies a 500 cents fixed discount only to the unit amount of the line item that has the lowest unit price among all the line items associated with an SKU and grouped as `discountable-items` within the related condition matchers:

<pre class="language-json"><code class="lang-json">"actions": [
  {
    "type": "fixed_amount",
    "selector": "order.line_items.sku",
    "groups": [ "discountable-items" ],
<strong>    "limit": {
</strong><strong>      "value": 1,
</strong><strong>      "sort" : {
</strong><strong>        "attribute": "unit_amount_cents",
</strong><strong>        "direction": "asc"
</strong><strong>      }
</strong>    },
    "value": 500  
  }
]
</code></pre>
