Creates a business rule and releases its first version, so the new rule has latest_version set to 1 and released_at set. The rule is created inactive: Chargebee does not evaluate it until you call Activate a business rule.
Use this operation to encode a decision that Chargebee should make repeatedly and consistently, such as the discount to offer on a qualifying quote or the constraint that a quote must satisfy before it is sent to a customer. The condition goes in structured_expression, and what should happen when the condition is met goes in actions_on_success.
Prerequisites & Constraints
Business rules must be enabled for the site.
Impacts
Business rule
A business rule is created with its first version released, so latest_version is 1 and released_at and released_by are set. The rule is created with active set to false, so Chargebee does not evaluate it yet.
Implementation Notes
- Call Activate a business rule to put the new rule into effect. Release a business rule is only needed later, once you have edited the rule and want the resulting draft to take effect.
- To check an expression against sample data before you store it as a rule, call Apply business rules with
structured_expressionand acontext, and withevaluateset totrueso that no actions are executed.
Sample Request
Sample Result[JSON]
URL Format
Input Parameters
A structured JSON representation of the rule logic, designed for visual editors and dynamic builders. Chargebee validates and compiles it when the rule is created. Pass it as a JSON object.
See Expressions for the node types and the operators each field type supports, and Context for the fields a condition can reference.
Impacts
- A condition whose
fieldis absent from the context passed to Apply business rules evaluates tofalse, so the rule never matches and no error is returned.
Example →
structured_expression = {"type":"GROUP","operation":"AND","children":[{"type":"CONDITION","field":"customer.language","operator":"CONTAINS","value":"en"},{"type":"CONDITION","field":"quote.shipping_address_country","operator":"ANY_OF","values":["IN","US"]}]}
The actions to execute when the rule expression evaluates to true, passed as a JSON array. Each action takes the action_template_id of the template it is built from and that template's parameters in input.
See Actions for the templates available, the parameters each one takes, and the optional action-level structured_expression that narrows the items an action applies to.
Example →
actions_on_success = [{"action_template_id":"action-apply-discount","input":{"apply_on":"invoice_amount","duration_type":"one_time","discount":12.0,"discount_type":"percentage"}}]
Returns
The newly created business rule, with its first version released so latest_version is 1, and with active set to false.