Actions
How to set a rule's actions and what are the required and optional parameters to set
For each rule you need to provide one or more actions
as an array of action objects.
Actions are triggered based on the provided rule's conditions. Once the combination of conditions are evaluated according to the conditions logic specified at the rule level, if they are satisfied, all the related actions will be applied to the specified resource's fields. Among other effects, actions can modify order totals, apply fixed, percentage, and other types of discounts to specific items, or adjust quantities.
Multiple actions (even involving the same resource's field) are applied in the order they are listed within the rule payload.
For each action you must define at least its type and the discount value to be applied. Based on the type of action some restrictions may apply, for example:
The list of required parameters may vary.
The required format/type for the value (if any) may vary.
Some optional key (e.g. bundle, limit, etc.) may be available or not.
type
"percentage"
selector
The resource on which to apply the action (expressed in dot notation). Can be an attribute if you set also the identifier
key.
"order.line_items"
"order.line_items.id"
identifier
An identifier value to address one or more specific instances of the resource based on the attribute defined in the selector
key (if any). Cannot be used if the selector is a resource.
"WVyPSgRwxZ"
groups
[ "discountable-items", "t-shirts" ]
bundle
Additional directives on how to recursively pick a subset of elements from the specified groups.
aggregation
Additional requirements on the aggregated items targeted by the action.
apply_on
The specific field of the selector resource on which to apply the action (available for specific action types only).
"compare_at_amount_cents"
discount_mode
"distributed"
limit
Additional restrictions on the number of items on which an action will be applied (available for specific action types only, cannot be used if the bundle
key is specified).
value
0.2
2500
{ "x": 3, "y": 2 }
Referring to the Core API integration, an action selector
can be a resource or an attribute. If it's a resource (i.e. anything but the last leaf of the relationship tree using the dot notation — e.g. order
or order.line_items
) the action will be applied on a default field (usually the unit amount of the resource), unless specified differently in the apply_on
key. If it's an attribute (e.g. or order.line_items.id
), you need to set also the identifier
key (e.g. WVyPSgRwxZ
) so that the action will be applied to the specified instance only.
For those conditions that don't have a group explicitly specified, the UUID autogenerated by the Core API integration will be automatically set as the group to which apply the action.
Examples
Selector
The following action applies a 10% discount to all the line items associated with an SKU:
Identifier
The following action sets to 1500 cents the unit amount of the line items associated with the SKU identified by the code XMASMUG1234
only:
Apply on
The following action applies a fixed amount discount of 1500 to the total amount (instead of the default unit amount) of all the line items associated with an SKU:
The following action applies a fixed amount discount of 1500 to the total amount (instead of the default unit amount) of the line items associated with the SKU identified by the code XMASMUG1234
only:
You can use apply_on
on percentage, fixed amount, and fixed price actions only.
Last updated