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

Create a business ruleset

Creates a business ruleset. A ruleset groups business rules so that they can be evaluated together, in the priority order you assign, using the strategy set in execute_mode.

Use this operation when a decision is made by several rules that belong together, such as all the checks that a quote must pass or the ladder of discounts that can apply to it. Once the ruleset exists, a single call to Apply business rules with its ruleset_id evaluates all of its rules.

Passing rules is optional. You can create an empty ruleset and fill it later with Add business rules to a ruleset.

Prerequisites & Constraints

  • Business rules must be enabled for the site.
  • Each rule referenced in rules must already exist.

Impacts

Business ruleset

A business ruleset is created with active set to false and with the rules you passed in rules as its membership.

Nothing is evaluated yet. A rule is evaluated through a ruleset only when both the ruleset and the rule itself are active, so each one has to be activated separately.

Implementation Notes

  • Create the rules first with Create a business rule, then reference their identifiers in rules. A rule_id that does not resolve to an existing rule is rejected.
  • Call Activate a business ruleset once the membership is in place, so that Chargebee starts evaluating the ruleset.

Use Cases

Evaluate every rule in the group

Leave execute_mode at its default of execute_all, or set it to execute_all_true if you only want the rules that matched to be returned. Use this when the rules are independent of one another, such as a set of validations that should all be reported.

Pick the first rule that matches

Set execute_mode to stop_on_first_true and assign the priorities so that the most specific rule is evaluated first. Evaluation stops at the first rule that matches, which makes the ruleset behave like an ordered list of alternatives.

Stop at the first failed check

Set execute_mode to stop_on_first_false so that evaluation stops at the first rule that is not satisfied. Use this when later rules only make sense if the earlier ones passed.

Sample Request

Sample Result[JSON]

URL Format

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

Input Parameters

id
optional, string, max chars=100

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

name
required, string, max chars=500

Display name of the business ruleset.

description
optional, string, max chars=1000

Description of what the business ruleset does.

execute_mode
optional, enumerated string, default=execute_all

Strategy that determines how the rules in the ruleset are evaluated and when evaluation stops.

Default value

  • execute_all.
Enum Values
stop_on_first_true

Evaluation stops as soon as a rule evaluates to true. The rules that come later in the evaluation order are not evaluated.

stop_on_first_false

Evaluation stops as soon as a rule evaluates to false. The rules that come later in the evaluation order are not evaluated.

execute_all

Every rule in the ruleset is evaluated and all the results are returned. This is the default.

execute_all_true

Every rule in the ruleset is evaluated, and only the rules that evaluated to true are returned.

rules
optional

The business rules that make up the ruleset, along with the priorities that determine their positions in its evaluation order. Each entry takes the rule_id of an existing business rule and an optional priority; when priority is omitted, it is assigned from the position of the entry in the array. Pass the list as a JSON array.

Constraints

  • Each rule_id must belong to a business rule that already exists.
  • A priority can be used by only one rule in the ruleset. Two entries that carry the same priority are rejected.

Example → rules = [{"rule_id":"custom-uuid-1","priority":1},{"rule_id":"custom-uuid-2","priority":2}]

Returns

Business ruleset object

The newly created business ruleset, with active set to false and with the rules you passed in rules as its membership.