Introducing OpenTelemetry for Chargebee SDKs — trace every API call in any telemetry tool.

Create a business rule

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_expression and a context, and with evaluate set to true so that no actions are executed.

Sample Request

Sample Result[JSON]

URL Format

POST https://[site].chargebee.com/api/v2/business_rules

Input Parameters

id
optional, string, max chars=100

Unique identifier for the business rule. If not provided, Chargebee generates one.

Constraints

  • The identifier of a deleted rule cannot be reused.
name
required, string, max chars=500

Display name of the business rule.

description
optional, string, max chars=1000

Description of what the business rule does.

structured_expression
required, jsonobject

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 field is absent from the context passed to Apply business rules evaluates to false, 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"]}]}

actions_on_success
optional

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

Business rule object

The newly created business rule, with its first version released so latest_version is 1, and with active set to false.