API · Catalogs and rules

Decision tables

Decision tables: definition, rows since a version and evaluation for a customer.

Decision table definition

GET/decision-tables/{code}

Decision table definition for the API client: the evaluation request parameters (all required and non-empty), the campaign parameter, the columns, the row result schema. The table is returned if it is enabled and available to at least one active project of the API client; otherwise — NOT_FOUND, as if it did not exist. Ability decisions:read.

Parameters

  • codestringpathrequired

    Decision table code (snake_case in Latin letters, up to 64 characters; converted to lower case). If there is no such table, the code fails the format, or the table is disabled or unavailable — NOT_FOUND with details.code as sent (first 64 characters).
    Example
    offer_matrix

Responses

  • 200

    Table definition

    application/json

    object

  • 401

    UNAUTHENTICATED — the Bearer token is missing or invalid

    Error format and codes

  • 403

    FORBIDDEN — the token lacks an ability (details.ability) or a project (details.project)

    Error format and codes

  • 404

    NOT_FOUND — the organization has no decision table with this code, the code does not match the format, the table is disabled or not available to the project (for GET — to any active project of the client, for evaluation — to the project from the body); details.code — as in the path, the first 64 characters

    Error format and codes

  • 422

    VALIDATION_FAILED — details.fields with errors by field

    Error format and codes

  • 429

    RATE_LIMITED — the client's rate limit is exceeded: details.limit — the limit per minute, details.retry_after — in how many seconds to retry; the same values are in the headers X-RateLimit-Limit and Retry-After.

    Headers

    • Retry-Afterinteger

      Seconds until the window resets
    • X-RateLimit-Limitinteger

    • X-RateLimit-Remaininginteger

    Error format and codes

Decision table rows since version N

GET/decision-tables/{code}/rows

A copy of decision table rows: rows changed after table version since, each in full — priority and all versions by number — in order of the table_version mark (the table version in which the row last changed: creation, a new version, a “valid to” edit, replacement of a version that has not started, priority, disabling, enabling), by code within it, with a cursor. The table is returned if it is enabled and available to at least one active project of the API client; otherwise — NOT_FOUND, as if it did not exist (this is no reason to clear the copy: the table may have been disabled or closed to the project; the decision_table.changed webhook reports that its version grew). Ability decisions:read. Rows cannot be written through the API — the CRM is the master of rows.

Syncing: meta.version is the table version read before the rows of the first page; all pages of the pass return the same value and rows in a state no newer than it. After the pass, the next sync uses since=<meta.version>. A row changed during the pass drops out of the remaining pages and arrives with the next sync. Rows are applied by code (or id) as a whole, by replacement. The CRM does not delete rows: a disabled row comes with closed versions, so local rows never need deleting. A request with since equal to the current version returns an empty list and the same version; the table version also grows without row changes (a definition edit, enabling) — then the list is empty, and the definition is re-read with GET /decision-tables/{code}. since greater than the table version — VALIDATION_FAILED under since: the copy comes from another database, and the rows are reloaded with since=0.

Full copy (meta.full_copy: true): if since is earlier than the version from which the table's rows are marked (a table whose rows were written before version marking began, and any table with since=0), all rows of the table are returned.

The size of a row grows with its history: a row that is edited often (scheduled import) has many versions — choose limit with this margin in mind.

Parameters

  • codestringpathrequired

    Decision table code (snake_case in Latin letters, up to 64 characters; converted to lower case). If there is no such table, the code fails the format, or the table is disabled or unavailable — NOT_FOUND with details.code as sent (first 64 characters).
    Example
    offer_matrix
  • sinceintegerqueryrequired

    Table version the client is already synced to (0 — from the beginning)
    Constraints
    minimum: 0
  • limitintegerquery

    List page size, 1…200; 50 when omitted
    Default
    50
    Constraints
    minimum: 1maximum: 200
  • cursorstringquery

    Opaque cursor from meta.cursor.next of the previous page; valid only with the same filters — otherwise VALIDATION_FAILED under cursor. Without the parameter — the first page.
    Constraints
    maxLength: 512

Responses

  • 200

    Page of rows

    application/json

    object

    • dataarray<DecisionTableRow>required

    • metaobjectrequired

      Service data of the response; for lists it contains cursor
      Fields
      • cursorobjectrequired

        Fields
        • nextstring | nullrequired

          Cursor of the next page, null — there are no more pages
      • redirected_fromstring (uuid)

        Only on a redirect: the request came with the ID of a customer merged into another one (in the path or in the body's customer_id), the response is for the primary one; the value is the original ID (normalized, lower case). Without a redirect the key is absent. A retry with the same Idempotency-Key returns the response stored by the first execution as is.
      • idempotent_replayboolean

        Only on a retry: the response is taken from the idempotency store, data is byte-for-byte the same as in the first response; or a retry by the interaction's natural key external_id — data is the existing interaction in its current state; or a repeated void of an already voided one. The first execution has no such field.
        Always
        true
      • versionintegerrequired

        Table version the rows are returned up to — since for the next sync
        Constraints
        minimum: 1
      • recordedinteger

        Only when recording consents: how many rows were inserted; 0 — the whole batch was already recorded (a retry by natural key).
        Constraints
        minimum: 0
      • effectsInteractionEffects

      • full_copybooleanrequired

        All rows of the table are returned, not only those changed after since
  • 401

    UNAUTHENTICATED — the Bearer token is missing or invalid

    Error format and codes

  • 403

    FORBIDDEN — the token lacks an ability (details.ability) or a project (details.project)

    Error format and codes

  • 404

    NOT_FOUND — the organization has no decision table with this code, the code does not match the format, the table is disabled or not available to the project (for GET — to any active project of the client, for evaluation — to the project from the body); details.code — as in the path, the first 64 characters

    Error format and codes

  • 422

    VALIDATION_FAILED — details.fields: since (missing, not an integer ≥ 0, greater than the table version), limit, cursor (from another request or corrupted), an unknown parameter — under its own name.

    Error format and codes

  • 429

    RATE_LIMITED — the client's rate limit is exceeded: details.limit — the limit per minute, details.retry_after — in how many seconds to retry; the same values are in the headers X-RateLimit-Limit and Retry-After.

    Headers

    • Retry-Afterinteger

      Seconds until the window resets
    • X-RateLimit-Limitinteger

    • X-RateLimit-Remaininginteger

    Error format and codes

Evaluate a decision table for a customer

POST/decision-tables/{code}/evaluate

Evaluates the table for a customer: matched — all matching rows in priority order (a smaller number first, ties broken by code) with the result and the state of limits; rejected — rows selected by the key columns that did not match, with the reason. Rows of another key and rows without a version in effect at moment go to neither list. Row versions are taken at moment, customer facts are current; the day of a day limit is the organization's local day that contains moment.

The evaluation writes nothing and does not take up the limit: creating an interaction that refers to the row takes it up, and the limit may run out between the evaluation and the creation. A client that evaluates before creating a backdated interaction passes moment = the future started_at. No Idempotency-Key.

Order of checks: the body's project (FORBIDDEN with details.project) → body shape → table (NOT_FOUND: missing, malformed code, disabled, unavailable to the body's project) → moment → table definition against the current configuration (VALIDATION_FAILED under table: a field, label or catalog was disabled after saving) → parameters (all errors at once under parameters.<name>: not passed, empty, not a scalar, wrong type, no such option or catalog item, unknown name) → customer (VALIDATION_FAILED under customer_id: missing or not active). Ability decisions:evaluate.

Parameters

  • codestringpathrequired

    Decision table code (snake_case in Latin letters, up to 64 characters; converted to lower case). If there is no such table, the code fails the format, or the table is disabled or unavailable — NOT_FOUND with details.code as sent (first 64 characters).
    Example
    offer_matrix

Request body

application/json

object

Extra key — VALIDATION_FAILED under its name
  • customer_idstring (uuid)required

  • projectstringrequired

    Code of an active project of the API client where the table is available
  • parametersobject | null

    Table parameter values by name (GET /decision-tables/{code} → parameters); all declared parameters are required and non-empty. reference — catalog item code, enum — an option, date — YYYY-MM-DD, numbers — as a number or a string.
  • momentstring (date-time)

    Moment for picking row versions (RFC 3339 with a time zone, to the second); no key — “now”; an empty string and null — VALIDATION_FAILED. No further into the future than the client clock tolerance — otherwise VALIDATION_FAILED under moment.

No other keys

Responses

  • 200

    Evaluation result (also when nothing matched)

    application/json

    object

  • 401

    UNAUTHENTICATED — the Bearer token is missing or invalid

    Error format and codes

  • 403

    FORBIDDEN — the token lacks an ability (details.ability) or a project (details.project)

    Error format and codes

  • 404

    NOT_FOUND — the organization has no decision table with this code, the code does not match the format, the table is disabled or not available to the project (for GET — to any active project of the client, for evaluation — to the project from the body); details.code — as in the path, the first 64 characters

    Error format and codes

  • 422

    VALIDATION_FAILED — details.fields with errors by field

    Error format and codes

  • 429

    RATE_LIMITED — the client's rate limit is exceeded: details.limit — the limit per minute, details.retry_after — in how many seconds to retry; the same values are in the headers X-RateLimit-Limit and Retry-After.

    Headers

    • Retry-Afterinteger

      Seconds until the window resets
    • X-RateLimit-Limitinteger

    • X-RateLimit-Remaininginteger

    Error format and codes

Schemas

DecisionTable

object

Decision table definition in canonical form. The field code in a column template is visible, including for a field hidden from the API; customer field values are never returned in the definition or in the evaluation response.
  • idstring (uuid)required

  • codestringrequired

    Example
    offer_matrix
  • nameLocalizedTextrequired

  • versionintegerrequired

    Table version counter — grows on any change to the definition and rows, and also when the table is enabled or disabled
    Constraints
    minimum: 1
  • parametersarray<object>required

    Evaluation request parameters in the declared order; in an evaluation all are required and non-empty (parameters of the body)
    Items
    • namestringrequired

    • typestringrequired

      Values
      stringintegerdecimalbooleandateenumreference
    • optionsarray<string>

      Only for enum — allowed values
    • catalogstring

      Only for reference — catalog code; the value is the code of its item
    • labelLocalizedText

      Parameter label for display; no key — the label is not set
  • campaign_parameterstring | nullrequired

    Name of the campaign parameter — limits with the campaign scope are counted by it
  • columnsarray<object>required

    Columns: key — a request key (context leaf by parameter), condition — a condition on the customer. The template is a condition language leaf without a value; the value is the row's cell. Column codes come in details.columns of a NOT_QUALIFIED rejection.
    Items
    • codestringrequired

    • rolestringrequired

      Values
      keycondition
    • templateobjectrequired

    • labelLocalizedText

      Column label for display; no key — the label is not set
  • result_schemaobjectrequired

    Row result schema (matched[].result of an evaluation): a {type} node — string, integer, decimal, boolean, date, enum (options), reference (catalog), list (items), object (fields: {code, type, required, …} — a node with a code and a required flag)
  • projectsarray<string>required

    Codes of the client's active projects where the table is available (evaluate in one of them)

LocalizedText

object

Label by platform language (ru, en); at least one language is non-empty
Example
{"ru":"Телефон","en":"Phone"}

Key values: string

Meta

object

Service data of the response; for lists it contains cursor
  • cursorobject

    Fields
    • nextstring | nullrequired

      Cursor of the next page, null — there are no more pages
  • redirected_fromstring (uuid)

    Only on a redirect: the request came with the ID of a customer merged into another one (in the path or in the body's customer_id), the response is for the primary one; the value is the original ID (normalized, lower case). Without a redirect the key is absent. A retry with the same Idempotency-Key returns the response stored by the first execution as is.
  • idempotent_replayboolean

    Only on a retry: the response is taken from the idempotency store, data is byte-for-byte the same as in the first response; or a retry by the interaction's natural key external_id — data is the existing interaction in its current state; or a repeated void of an already voided one. The first execution has no such field.
    Always
    true
  • versioninteger

    Only in catalog lists: the catalog version — for items it is read before the rows of the first page of the traversal, for changes it is the upper bound of the feed. The next sync is changes?since=<version>.
    Constraints
    minimum: 0
  • recordedinteger

    Only when recording consents: how many rows were inserted; 0 — the whole batch was already recorded (a retry by natural key).
    Constraints
    minimum: 0
  • effectsInteractionEffects

InteractionEffects

object

Effects of the operation: what rules and accounts did in its transaction. On a retry by external_id the deltas are empty. Rules are recalculated when an interaction is created, edited and voided: labels_added and labels_removed are labels the customer gained and lost; a change of a rule row that did not make a label appear or disappear (a manual row exists alongside, a row of another rule is overwritten) is visible only in rules_fired. balances — changes to the customer's balances made by the operation (redemptions and accruals on create, offsetting entries on void), one element per kind in ascending order of the code; empty on a retry and an edit. assets — asset changes made by the operation (actions on item serial numbers on create, their reversal on void) in recording order; empty on a retry and an edit. labels and current_balances — the customer's state after the operation, returned on a retry too.
  • labels_addedarray<CustomerLabel>required

    Labels the customer gained in the operation
  • labels_removedarray<string>required

    Codes of labels the customer lost in the operation
  • balancesarray<BalanceChange>required

    Balance changes of the operation by account kind
  • assetsarray<AssetChange>required

    Asset changes of the operation
  • rules_firedarray<RuleFired>required

    Changes to label rows made by rules, in order of application
  • labelsarray<CustomerLabel>required

    The customer's active labels after the operation
  • current_balancesarray<CustomerBalance>required

    The customer's current balances after the operation — like balances of the customer card: one element for each active account kind, zero without entries

CustomerLabel

object

Active customer label — one item per code; expired labels are not in the response. A label can have two rows — manual and rule; the label is active while at least one of them is. The top-level fields come from the manual row if there is one, otherwise from the rule row; sources — each active row.
  • codestringrequired

    Label type code (lower case)
  • kindstringrequired

    Kind from the type settings — blocking operations, a group, a flag
    Values
    blocksegmentflag
  • reasonstring | nullrequired

  • expires_atstring (date-time) | nullrequired

    ISO 8601, UTC; null — no expiry
  • sourcestringrequired

    Set manually or by a rule
    Values
    manualrule
  • created_byActorrequired

  • created_atstring (date-time)required

    Moment the label was set, ISO 8601, UTC
  • sourcesarray<CustomerLabelSource>required

    Active label rows by source — the manual one first

Actor

object

Who performed the operation — an API client, an admin panel user or the system
  • kindstringrequired

    Values
    api_clientusersystem
  • idstring | nullrequired

    ID of the API client (UUID) or user; null for system

CustomerLabelSource

object

Label row of one source: a person sets and removes the manual row, only the rule sets and removes the rule row (it cannot be removed via DELETE …/labels/{code}).
  • sourcestringrequired

    Values
    manualrule
  • rule_idstring (uuid) | nullrequired

    Rule that set the row; null for the manual one
  • reasonstring | nullrequired

  • expires_atstring (date-time) | nullrequired

    ISO 8601, UTC; null — no expiry
  • created_byActorrequired

  • created_atstring (date-time)required

    Moment the row was set, ISO 8601, UTC

BalanceChange

object

A change of the customer's balance of one account kind in the operation: change — the sum of the operation's entries for the kind (signed; a redemption and an accrual of one kind make one element), balance — the balance after; decimal as a string with exactly the kind's scale, unit — as in CustomerBalance. A kind with corrupted settings (a void goes through for it as well) — in canonical form, unit: null.
  • account_kindstringrequired

  • changestringrequired

    Example
    -3000
  • balancestringrequired

    Example
    2000
  • unitobject | nullrequired

    As unit in CustomerBalance — one unit form per language, not inflected by number

    Key values: string

AssetChange

object

An asset change made by an interaction operation: registered — registration (status_from: null) or re-linking of an ownerless asset, transitioned — a transition of the customer's asset, reverted — undone on void; customer_id — the owner after the change
  • idstring (uuid)required

  • typestringrequired

    Asset type code
  • serialstringrequired

    Serial number as recorded
  • eventstringrequired

    Values
    registeredtransitionedreverted
  • status_fromstring | nullrequired

  • status_tostringrequired

  • customer_idstring (uuid) | nullrequired

RuleFired

object

A rule that fired: the rule's label row was set (set) or removed (removed).
  • rulestringrequired

    Rule code
  • rule_idstring (uuid)required

    Rule ID — same as sources[].rule_id of a customer label
  • labelstringrequired

    Label code
  • actionstringrequired

    Values
    setremoved

CustomerBalance

object

Customer balance by account kind. There is no kind label — as with the card's labels and consents, kind labels are in the schema (GET /v1/schema).
  • account_kindstringrequired

    Account kind code (entity_types:account_kind)
    Example
    points
  • balancestringrequired

    Balance — a decimal as a string with exactly the kind's number of decimal places (scale): "0" for a kind with no decimal places, "100.50" for a kind with two; can be negative (a minus allowed by the kind, or a reversal).
    Example
    100100.50-40.00
  • unitobject | nullrequired

    Unit label for displaying the balance — a “language → text” object with any languages; null — not set. One form per language, as set on the account kind: plural forms by number (“1 point”, “5 points”) are not returned by the API — the forms are in the account kind settings, and only the admin panel uses them.
    Example
    {"ru":"балл","en":"pts"}

    Key values: string

DecisionTableRow

object

Decision table row in a “since version N” listing: whole, with all versions. There is no status — it changes over time without the table version growing and is derived from version validity at the needed moment.
  • idstring (uuid)required

    Row ID — passed in decision_line_id of an interaction
  • codestringrequired

    Row code, unique within the table (case-sensitive)
  • priorityintegerrequired

    A lower number comes first; on a tie — by code
    Constraints
    minimum: 0
  • table_versionintegerrequired

    Table version in which the row last changed
    Constraints
    minimum: 1
  • versionsarray<DecisionTableRowVersion>required

    Versions in ascending number order; validity periods [valid_from, valid_to) do not overlap

DecisionTableRowVersion

object

  • numberintegerrequired

    Constraints
    minimum: 1
  • cellsobjectrequired

    Cells by column code; no column — “any”
  • resultobjectrequired

    Version result by the table's result_schema
  • limitsarray<object>required

    Per-customer limits of the version; empty — no limits
    Items
    • scopestringrequired

      Values
      campaigndaytotal
    • maxintegerrequired

      Constraints
      minimum: 1
  • valid_fromstring (date-time)required

    Start of version validity (UTC); an empty period (valid_from = valid_to) — the version was never in effect
  • valid_tostring (date-time) | nullrequired

    End of validity (UTC, exclusive); null — no expiry
  • recorded_atstring (date-time)required

    Moment the version was recorded (UTC)

DecisionEvaluation

object

Decision table evaluation result
  • tableobjectrequired

    Fields
    • codestringrequired

    • versionintegerrequired

      Constraints
      minimum: 1
  • momentstring (date-time)required

    Moment for which row versions are selected (UTC)
  • matchedarray<DecisionMatchedRow>required

    Matching rows by priority
  • rejectedarray<DecisionRejectedRow>required

    Rows selected by key but not matched, in the same order

DecisionMatchedRow

object

  • idstring (uuid)required

    Row ID — passed in decision_line_id of an interaction
  • codestringrequired

    Row code from the organization's file (case-sensitive)
  • priorityintegerrequired

  • resultobjectrequired

    Row version result by the table's result_schema
  • limitsarray<DecisionLimitState>required

    State of the row version's limits (none is exhausted); empty — no limits. A campaign limit on a table without a campaign parameter (a closed version when evaluating at a past moment) is not counted and not shown here

DecisionLimitState

object

  • scopestringrequired

    campaign — the campaign parameter value, day — the organization's local day, total — all time
    Values
    campaigndaytotal
  • maxintegerrequired

    Constraints
    minimum: 1
  • usedintegerrequired

    Unreleased issues of the row to the customer within the scope
    Constraints
    minimum: 0

DecisionRejectedRow

object

  • idstring (uuid)required

  • codestringrequired

  • priorityintegerrequired

  • reasonstringrequired

    One reason by precedence — BLOCKED, then NOT_QUALIFIED, then LIMIT_REACHED
    Values
    BLOCKEDNOT_QUALIFIEDLIMIT_REACHED
  • detailsobjectrequired

    The same shape as an error with this code (the details description of Error): the common part customer_id, row_id, row_code, plus labels (BLOCKED), columns (NOT_QUALIFIED) or limits (LIMIT_REACHED)
    Fields
    • customer_idstring (uuid)required

    • row_idstring (uuid)required

    • row_codestringrequired

    • labelsarray<string>

      Codes of block kind labels from the labels column cell that the customer has
    • columnsarray<object>

      Columns that gave “false”, with the cell value; the customer's fact is not included
      Items
      • columnstringrequired

      • leafstringrequired

      • opstringrequired

      • valueany valuerequired

      • detailsobject

        For history — the filter after parameter substitution
    • limitsarray<DecisionLimitState>

      Exhausted limits