Limit

How to limit the number of targets of an action

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).

Key
Type
Required
Description
Example

value

Integer

The number of items on which to apply the action, according to the logic specified in the sort object.

2

sort

Object

The sorting logic to apply before executing the limit.

Learn more here.

Sort

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

Key
Type
Required
Description
Example

attribute

String

The field of the resource specified in the action's selector on which to apply the limit sorting. Works with numeric fields only.

"unit_amount_cents"

direction

String

The sorting function to be used. Can be one of asc or desc.

"asc"

You can set a limit on percentage, fixed amount, and fixed price actions only, provided that you're not using bundles.

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:

"actions": [
  {
    "type": "fixed_amount",
    "selector": "order.line_items.sku",
    "groups": [ "discountable-items" ],
    "limit": {
      "value": 1,
      "sort" : {
        "attribute": "unit_amount_cents",
        "direction": "asc"
      }
    },
    "value": 500  
  }
]

Last updated