← Back to Docs

smartRules API Reference

Business rules engine for application platforms. Create use cases, build rulesets, evaluate rules against factbases, and parse human-readable expressions into structured rule objects.

Base URLs

EnvironmentBase URL
Sandboxhttps://so-preproduction-rules-webapp-west.azurewebsites.net
ProductionProvided by your smartObjx account administrator

All endpoints require authentication headers: Ocp-Apim-Subscription-Key and Ocp-Apim-POV-Key.

Domain Model

UseCase
Entry point for a body of rules executed in an application workflow. Applications may have multiple UseCases, each with a separate collection of rules. Separating complex rules into separate UseCases helps keep rulesets easy to manage and maintain.
RuleSet
A collection of rules or nested rulesets. There is no limit on the number of inner child RuleSets. RuleSets break complex logic into smaller components which are easy to understand and maintain. Each UseCase contains a single top-level RuleSet.
Rule
A statement of conditional logic, purported to be true or false. Rules may contain multiple conditions (PropositionConstants) connected by operators (AND, OR). Any rule with multiple conditions may instead be built as a RuleSet with multiple single-condition rules, and vice versa.
AbstractRule
Base class for both Rule and RuleSet. Used as the type parameter when serializing rules: typeof(AbstractRule).
PropositionConstant
A named condition within a Rule. Has a name (e.g., "Age") and a truth value. Added to rules via rule.AddPropositionConstantNamed("A", value: true).
Factbase
Input data passed to a rule for evaluation. POST the Factbase to a rule's OID endpoint to get back a PropositionConstant (true/false result).

The Structure of Rules

Complex logic is assembled by packaging small pieces in a nested hierarchical structure:

UseCase
  └── RuleSet (top-level)
        ├── Rule (with PropositionConstants + Operators)
        ├── RuleSet (nested)
        │     ├── Rule
        │     └── Rule
        └── Rule

Each UseCase contains a single top-level RuleSet. That RuleSet may contain Rules, other RuleSets, or a combination of both. Rules can be edited by creating a version with a start date for the change to become active.


Endpoints

GET /usecases

List all Use Cases. Returns a JSON array of UseCase objects.

Response example

[
  {
    "$id": "1",
    "Name": "US Federal Taxes",
    "RuleID": "7a8d3a09-9bd7-448f-8586-6e8cb2a2d3ac",
    "OID": "0a36b055-f7fd-48b6-8937-f123b0f65b1f",
    "SubscriberID": "33f13e11-c505-48fa-9e6b-85f0b1c4599c",
    "OwnerID": "45ef2936-160e-47dc-bd17-3dc0060acec9",
    "Version": "2020-11-18T14:07:01"
  },
  {
    "$id": "2",
    "Name": "Credit Card Application",
    "RuleID": "ad3e41b1-add1-46d9-bc05-ae1ba26a8c27",
    "OID": "ac50b257-5d94-4e24-ade8-8b97ca538597",
    "SubscriberID": "33f13e11-c505-48fa-9e6b-85f0b1c4599c",
    "OwnerID": "45ef2936-160e-47dc-bd17-3dc0060acec9",
    "Version": "2020-11-18T14:07:11"
  },
  {
    "$id": "3",
    "Name": "Feature Scoring Model",
    "RuleID": "bc59f002-3f5d-49fe-bfc2-211d65833619",
    "OID": "22f6c3d5-880f-42f6-8234-33bee4fb8dee",
    "SubscriberID": "33f13e11-c505-48fa-9e6b-85f0b1c4599c",
    "OwnerID": "45ef2936-160e-47dc-bd17-3dc0060acec9",
    "Version": "2020-11-20T19:40:24"
  }
]

POST /usecases

Create a new Use Case. Returns 201 Created with the new UseCase object.

C# example

UseCase useCase = new UseCase { Name = "FederalTaxUseCase" };
string payload = JsonConvert.SerializeObject(useCase, typeof(UseCase),
    JsonSerializationSettingsFactory.GetSettingsInstance());
HttpResponseMessage result = await client.PostAsync("usecases",
    new StringContent(payload, Encoding.UTF8, "application/json"));

POST /rules

Create or save a RuleSet or Rule. The body must be serialized using typeof(AbstractRule) and the smartObjx serialization settings to include the $type discriminator.

C# example — Create a RuleSet with nested Rules

RuleSet ruleSet = new RuleSet("Parent Ruleset");
RuleSet ruleSetChild = new RuleSet("Ruleset with Rules");
ruleSet.AddRule(ruleSetChild);

string payload = JsonConvert.SerializeObject(ruleSet, typeof(AbstractRule),
    JsonSerializationSettingsFactory.GetSettingsInstance());
HttpResponseMessage result = await client.PostAsync("rules",
    new StringContent(payload, Encoding.UTF8, "application/json"));

C# example — Add a Rule with conditions and operators

RuleSet ruleSet = new RuleSet("Parent Ruleset");
Rule rule = new Rule("smart.Objx.Rules.True");
rule.AddPropositionConstantNamed("A", value: true);
rule.AddPropositionConstantNamed("B", value: true);
rule.AddOperatorNamed("OR");
ruleSet.AddRule(rule);

string payload = JsonConvert.SerializeObject(ruleSet, typeof(AbstractRule),
    JsonSerializationSettingsFactory.GetSettingsInstance());
HttpResponseMessage result = await client.PostAsync("rules",
    new StringContent(payload, Encoding.UTF8, "application/json"));

Returns 201 Created with the saved rule object. Deserialize with:

string content = await result.Content.ReadAsStringAsync();
AbstractRule found = JsonConvert.DeserializeObject<AbstractRule>(content,
    JsonSerializationSettingsFactory.GetSettingsInstance());

POST /rules/{oid}

Evaluate a rule by posting a Factbase to it. Returns a PropositionConstant with the evaluation result (true/false).

Parameters

ParameterTypeDescription
oidpath (GUID)The OID of the rule to evaluate

C# example

Factbase factbase = new Factbase();
string payload = JsonConvert.SerializeObject(factbase, typeof(Factbase),
    JsonSerializationSettingsFactory.GetSettingsInstance());
HttpResponseMessage result = await client.PostAsync(
    $"rules/{rule.OID.ToString()}",
    new StringContent(payload, Encoding.UTF8, "application/json"));

string content = await result.Content.ReadAsStringAsync();
PropositionConstant evaluated =
    JsonConvert.DeserializeObject<PropositionConstant>(content);
// evaluated is true or false

POST /parse

Parse a human-readable rule expression into a structured Rule object.

C# example

string exp = "Age > 21";
HttpResponseMessage result = await client.PostAsync("parse",
    new StringContent($"\"{exp}\"", Encoding.UTF8, "application/json"));
string content = await result.Content.ReadAsStringAsync();
AbstractRule found = JsonConvert.DeserializeObject<AbstractRule>(content,
    JsonSerializationSettingsFactory.GetSettingsInstance());
Rule parsedRule = (Rule)found;

More expression examples

  • "Score >= 700"
  • "Amount < 10000"
  • "Status = Active"

JavaScript Integration

async function getData(url = '', data = {}) {
  const response = await fetch(url, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'Ocp-Apim-Subscription-Key': 'fd8efd80-f215-4c73-95f2-23841e98acbd',
      'Ocp-Apim-POV-Key': '45ef2936-160e-47dc-bd17-3dc0060acec9'
    },
  });
  return response.json();
}

// List all Use Cases
getData('https://so-preproduction-rules-webapp-west.azurewebsites.net/usecases')
  .then(data => console.log(data));

Use Cases

  • US Federal Tax calculations
  • Credit card application approval logic
  • Feature scoring models
  • Dynamic pricing rules per customer tier
  • Compliance rules that vary by jurisdiction
  • Approval workflows with configurable thresholds

Browser IDE

smartRules includes a browser-based IDE for building and testing rules visually. Try the sandbox IDE at rules-demo.smartobjx.com.

Related