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
codestringpathrequiredDecision 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_FOUNDwithdetails.codeas sent (first 64 characters).- Example
offer_matrix
Responses
200
Table definition
application/jsonobject
dataDecisionTablerequiredmetaMetarequired
401
UNAUTHENTICATED — the Bearer token is missing or invalid
403
FORBIDDEN — the token lacks an ability (
details.ability) or a project (details.project)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 characters422
VALIDATION_FAILED —
details.fieldswith errors by field429
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 headersX-RateLimit-LimitandRetry-After.Headers
Retry-AfterintegerSeconds until the window resetsX-RateLimit-LimitintegerX-RateLimit-Remaininginteger
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
codestringpathrequiredDecision 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_FOUNDwithdetails.codeas sent (first 64 characters).- Example
offer_matrix
sinceintegerqueryrequiredTable version the client is already synced to (0 — from the beginning)- Constraints
minimum: 0
limitintegerqueryList page size, 1…200; 50 when omitted- Default
50- Constraints
minimum: 1maximum: 200
cursorstringqueryOpaque cursor frommeta.cursor.nextof the previous page; valid only with the same filters — otherwiseVALIDATION_FAILEDundercursor. Without the parameter — the first page.- Constraints
maxLength: 512
Responses
200
Page of rows
application/jsonobject
dataarray<DecisionTableRow>requiredmetaobjectrequiredService data of the response; for lists it containscursorFields
cursorobjectrequiredFields
nextstring | nullrequiredCursor 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'scustomer_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 sameIdempotency-Keyreturns the response stored by the first execution as is.idempotent_replaybooleanOnly on a retry: the response is taken from the idempotency store,datais byte-for-byte the same as in the first response; or a retry by the interaction's natural keyexternal_id—datais 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
versionintegerrequiredTable version the rows are returned up to —sincefor the next sync- Constraints
minimum: 1
recordedintegerOnly when recording consents: how many rows were inserted; 0 — the whole batch was already recorded (a retry by natural key).- Constraints
minimum: 0
effectsInteractionEffectsfull_copybooleanrequiredAll rows of the table are returned, not only those changed aftersince
401
UNAUTHENTICATED — the Bearer token is missing or invalid
403
FORBIDDEN — the token lacks an ability (
details.ability) or a project (details.project)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 characters422
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.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 headersX-RateLimit-LimitandRetry-After.Headers
Retry-AfterintegerSeconds until the window resetsX-RateLimit-LimitintegerX-RateLimit-Remaininginteger
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
codestringpathrequiredDecision 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_FOUNDwithdetails.codeas sent (first 64 characters).- Example
offer_matrix
Request body
application/json
object
VALIDATION_FAILED under its namecustomer_idstring (uuid)requiredprojectstringrequiredCode of an active project of the API client where the table is availableparametersobject | nullTable 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 andnull—VALIDATION_FAILED. No further into the future than the client clock tolerance — otherwiseVALIDATION_FAILEDundermoment.
No other keys
Responses
200
Evaluation result (also when nothing matched)
application/jsonobject
dataDecisionEvaluationrequiredmetaMetarequired
401
UNAUTHENTICATED — the Bearer token is missing or invalid
403
FORBIDDEN — the token lacks an ability (
details.ability) or a project (details.project)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 characters422
VALIDATION_FAILED —
details.fieldswith errors by field429
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 headersX-RateLimit-LimitandRetry-After.Headers
Retry-AfterintegerSeconds until the window resetsX-RateLimit-LimitintegerX-RateLimit-Remaininginteger
Schemas
DecisionTable
object
idstring (uuid)requiredcodestringrequired- Example
offer_matrix
nameLocalizedTextrequiredversionintegerrequiredTable 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>requiredEvaluation request parameters in the declared order; in an evaluation all are required and non-empty (parametersof the body)Items
namestringrequiredtypestringrequired- Values
stringintegerdecimalbooleandateenumreference
optionsarray<string>Only forenum— allowed valuescatalogstringOnly forreference— catalog code; the value is the code of its itemlabelLocalizedTextParameter label for display; no key — the label is not set
campaign_parameterstring | nullrequiredName of the campaign parameter — limits with thecampaignscope are counted by itcolumnsarray<object>requiredColumns:key— a request key (contextleaf 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 indetails.columnsof aNOT_QUALIFIEDrejection.Items
codestringrequiredrolestringrequired- Values
keycondition
templateobjectrequiredlabelLocalizedTextColumn label for display; no key — the label is not set
result_schemaobjectrequiredRow result schema (matched[].resultof 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>requiredCodes of the client's active projects where the table is available (evaluate in one of them)
LocalizedText
object
ru, en); at least one language is non-empty- Example
{"ru":"Телефон","en":"Phone"}
Key values: string
Meta
object
cursorcursorobjectFields
nextstring | nullrequiredCursor 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'scustomer_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 sameIdempotency-Keyreturns the response stored by the first execution as is.idempotent_replaybooleanOnly on a retry: the response is taken from the idempotency store,datais byte-for-byte the same as in the first response; or a retry by the interaction's natural keyexternal_id—datais 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
versionintegerOnly 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 ischanges?since=<version>.- Constraints
minimum: 0
recordedintegerOnly 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
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>requiredLabels the customer gained in the operationlabels_removedarray<string>requiredCodes of labels the customer lost in the operationbalancesarray<BalanceChange>requiredBalance changes of the operation by account kindassetsarray<AssetChange>requiredAsset changes of the operationrules_firedarray<RuleFired>requiredChanges to label rows made by rules, in order of applicationlabelsarray<CustomerLabel>requiredThe customer's active labels after the operationcurrent_balancesarray<CustomerBalance>requiredThe customer's current balances after the operation — likebalancesof the customer card: one element for each active account kind, zero without entries
CustomerLabel
object
sources — each active row.codestringrequiredLabel type code (lower case)kindstringrequiredKind from the type settings — blocking operations, a group, a flag- Values
blocksegmentflag
reasonstring | nullrequiredexpires_atstring (date-time) | nullrequiredISO 8601, UTC; null — no expirysourcestringrequiredSet manually or by a rule- Values
manualrule
created_byActorrequiredcreated_atstring (date-time)requiredMoment the label was set, ISO 8601, UTCsourcesarray<CustomerLabelSource>requiredActive label rows by source — the manual one first
Actor
object
kindstringrequired- Values
api_clientusersystem
idstring | nullrequiredID of the API client (UUID) or user; null forsystem
CustomerLabelSource
object
DELETE …/labels/{code}).sourcestringrequired- Values
manualrule
rule_idstring (uuid) | nullrequiredRule that set the row; null for the manual onereasonstring | nullrequiredexpires_atstring (date-time) | nullrequiredISO 8601, UTC; null — no expirycreated_byActorrequiredcreated_atstring (date-time)requiredMoment the row was set, ISO 8601, UTC
BalanceChange
object
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_kindstringrequiredchangestringrequired- Example
-3000
balancestringrequired- Example
2000
unitobject | nullrequiredAsunitinCustomerBalance— one unit form per language, not inflected by numberKey values: string
AssetChange
object
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 changeidstring (uuid)requiredtypestringrequiredAsset type codeserialstringrequiredSerial number as recordedeventstringrequired- Values
registeredtransitionedreverted
status_fromstring | nullrequiredstatus_tostringrequiredcustomer_idstring (uuid) | nullrequired
RuleFired
object
set) or removed (removed).rulestringrequiredRule coderule_idstring (uuid)requiredRule ID — same assources[].rule_idof a customer labellabelstringrequiredLabel codeactionstringrequired- Values
setremoved
CustomerBalance
object
GET /v1/schema).account_kindstringrequiredAccount kind code (entity_types:account_kind)- Example
points
balancestringrequiredBalance — 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 | nullrequiredUnit 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
idstring (uuid)requiredRow ID — passed indecision_line_idof an interactioncodestringrequiredRow code, unique within the table (case-sensitive)priorityintegerrequiredA lower number comes first; on a tie — by code- Constraints
minimum: 0
table_versionintegerrequiredTable version in which the row last changed- Constraints
minimum: 1
versionsarray<DecisionTableRowVersion>requiredVersions in ascending number order; validity periods[valid_from, valid_to)do not overlap
DecisionTableRowVersion
object
numberintegerrequired- Constraints
minimum: 1
cellsobjectrequiredCells by column code; no column — “any”resultobjectrequiredVersion result by the table'sresult_schemalimitsarray<object>requiredPer-customer limits of the version; empty — no limitsItems
scopestringrequired- Values
campaigndaytotal
maxintegerrequired- Constraints
minimum: 1
valid_fromstring (date-time)requiredStart of version validity (UTC); an empty period (valid_from=valid_to) — the version was never in effectvalid_tostring (date-time) | nullrequiredEnd of validity (UTC, exclusive);null— no expiryrecorded_atstring (date-time)requiredMoment the version was recorded (UTC)
DecisionEvaluation
object
tableobjectrequiredFields
codestringrequiredversionintegerrequired- Constraints
minimum: 1
momentstring (date-time)requiredMoment for which row versions are selected (UTC)matchedarray<DecisionMatchedRow>requiredMatching rows by priorityrejectedarray<DecisionRejectedRow>requiredRows selected by key but not matched, in the same order
DecisionMatchedRow
object
idstring (uuid)requiredRow ID — passed indecision_line_idof an interactioncodestringrequiredRow code from the organization's file (case-sensitive)priorityintegerrequiredresultobjectrequiredRow version result by the table'sresult_schemalimitsarray<DecisionLimitState>requiredState of the row version's limits (none is exhausted); empty — no limits. Acampaignlimit 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
scopestringrequiredcampaign— the campaign parameter value,day— the organization's local day,total— all time- Values
campaigndaytotal
maxintegerrequired- Constraints
minimum: 1
usedintegerrequiredUnreleased issues of the row to the customer within the scope- Constraints
minimum: 0
DecisionRejectedRow
object
idstring (uuid)requiredcodestringrequiredpriorityintegerrequiredreasonstringrequiredOne reason by precedence —BLOCKED, thenNOT_QUALIFIED, thenLIMIT_REACHED- Values
BLOCKEDNOT_QUALIFIEDLIMIT_REACHED
detailsobjectrequiredThe same shape as an error with this code (thedetailsdescription ofError): the common partcustomer_id,row_id,row_code, pluslabels(BLOCKED),columns(NOT_QUALIFIED) orlimits(LIMIT_REACHED)Fields
customer_idstring (uuid)requiredrow_idstring (uuid)requiredrow_codestringrequiredlabelsarray<string>Codes ofblockkind labels from the labels column cell that the customer hascolumnsarray<object>Columns that gave “false”, with the cell value; the customer's fact is not includedItems
columnstringrequiredleafstringrequiredopstringrequiredvalueany valuerequireddetailsobjectForhistory— the filter after parameter substitution
limitsarray<DecisionLimitState>Exhausted limits