Need to create rules based on bundles?
Learn more
LogoLogo
APIsChangelog
  • Getting started
  • Rules
  • Conditions
    • Scope
    • Aggregations
    • Nested
    • Dynamic values
  • Actions
    • Types
      • Percentage
      • Fixed amount
      • Fixed price
      • Buy X pay Y
      • Every X discount Y
    • Bundle
      • Balanced
      • Every
    • Aggregation
    • Limit
  • Matchers
  • Operators
  • Check and validation
  • Core API integration
    • Order rules
    • Price rules
    • Virtual relationships
  • Resources
    • Promotions
    • Price lists
  • Use cases
    • Promotions
      • Discount line items based on item's price
      • Get a discount when paying by credit card
      • Discount an order based on promo item and total number of items
      • Offer a specific shipping method for free in a specific country
      • Discount items with large stock availability
      • Discount all the SKU in an order based on the shipping country
      • Discount all the SKU in an order based on the customer email domain
    • Price lists
      • Discount all prices greater than or equal to a specific value
      • Discount specific SKUs for new clients
      • Change strike-through price based on customer email domain
On this page
  • Sort
  • Example
  1. Actions

Limit

How to limit the number of targets of an action

PreviousAggregationNextMatchers

Last updated 2 months ago

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.

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 , , and actions only, provided that you're not using .

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  
  }
]

Learn more .

percentage
fixed amount
fixed price
bundles
here