API · Interactions and accounting

Accounts

Customer balance by account kind, manual entries and their reversals.

Customer entries

GET/customers/{id}/ledger-entries

A page of the customer's entries across all their accounts, newest first (created_at descending, ties — by id), cursor pagination: meta.cursor.next is passed as the cursor parameter with the same account_kind until it becomes null. Ability ledgers:read. Manual entries are visible to everyone with the ability; an entry bound to an interaction (redemption, accrual and their reversing entries) — only if the interaction is in projects assigned to the API client (including deactivated ones). Entries of disabled account kinds stay in the list. The customer is not in the organization — NOT_FOUND with details.id. account_kind — a kind code (an unknown one gives an empty list, a malformed one gives an error). Errors — VALIDATION_FAILED with details.fields.<parameter>, before the customer check: first the request shape (a parameter outside the list — “Unknown parameter”), then the values — all at once (kind, limit range, cursor).

Parameters

  • idstring (uuid)pathrequired

  • account_kindstringquery

  • 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

    A page of entries

    application/json

    object

    • dataarray<LedgerEntry>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
      • 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

  • 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 — resource or route not found

    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

Manual entry

POST/customers/{id}/ledger-entries

A manual entry on the customer's account — kind manual: an accrual (amount greater than zero) or a redemption (less than zero) by the API client outside an interaction. Ability ledgers:write; the Idempotency-Key header is required; a manual entry has no project. The account is opened by its first entry.

amount — a decimal as a string: digits, an optional leading minus, a fractional part after a dot ("100", "-40.50"); +100, .5, an exponent, zero and a JSON number — VALIDATION_FAILED under amount, as are more digits after the dot than the kind's scale (no rounding) and an absolute value from 10^14. reason — the reason, 1–1000 characters. external_id — an optional natural key of the accounting system (up to 128 characters, unique within the organization): a repeat with the same key and the same body (account_kind, amount, reason as sent, after trimming whitespace at the edges; the same customer) — 200 with the same entry and meta.idempotent_replay: true; with a different body or for another customer — CONFLICT with details.external_id and details.existing_id. The key is checked before the state: a retry of a redemption that already went through does not get INSUFFICIENT_BALANCE.

Order of refusals: body shape (VALIDATION_FAILED) — natural key (CONFLICT; checked before the customer from the path and the amount) — amount format (under amount) — customer (NOT_FOUND; not active — VALIDATION_FAILED under customer) — kind (unknown or disabled — under account_kind) — amount value (zero, digits beyond scale, the limit — under amount) — balance: a redemption that takes the balance negative for a kind where negative balances are not allowed — INSUFFICIENT_BALANCE with details.account_kind, details.balance (before the operation) and details.requested (the absolute redemption amount), nothing is written. Response 201 — the entry and meta.balance — the kind's balance after it (on a repeat — the current one).

The customer from the path is merged: the new entry is written to the primary, meta.redirected_from — the ID from the path. A repeat by external_id of an entry written to the absorbed customer before the merge — the same entry (its customer is the absorbed one: entries do not move), meta.balance — the kind's balance of the primary (the absorbed customer's account is zero after the transfer; after a chain of merges — of the last primary) and meta.redirected_from — the ID from the path.

Parameters

  • idstring (uuid)pathrequired

  • Idempotency-Keystringheaderrequired

    Idempotency key: unique within the client, lives for 24 hours. A repeat with the same key and request returns the saved response with meta.idempotent_replay: true; a different request with the same key gets IDEMPOTENCY_MISMATCH. A UUID is recommended.
    Constraints
    minLength: 1maxLength: 255

Request body

application/json

LedgerEntryInput

  • account_kindstringrequired

    Code of an active account kind (entity_types:account_kind)
    Example
    points
  • amountstringrequired

    Signed amount — a decimal as a string; plus is an accrual, minus is a redemption, zero is not allowed
    Constraints
    pattern: ^-?[0-9]+(\.[0-9]+)?$
    Example
    100-40.50
  • reasonstringrequired

    Constraints
    minLength: 1maxLength: 1000
  • external_idstring | null

    Natural key of the accounting system, unique within the organization
    Constraints
    maxLength: 128

Responses

  • 200

    Repeat by external_id — the recorded entry, meta.idempotent_replay

    application/json

    LedgerEntryResponse

    • dataLedgerEntryrequired

    • metaobjectrequired

      Service data of the response; for lists it contains cursor
      Fields
      • 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

      • balanceCustomerBalancerequired

  • 201

    Entry recorded

    application/json

    LedgerEntryResponse

    • dataLedgerEntryrequired

    • metaobjectrequired

      Service data of the response; for lists it contains cursor
      Fields
      • 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

      • balanceCustomerBalancerequired

  • 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 — resource or route not found

    Error format and codes

  • 409

    CONFLICT — external_id is taken by an entry with a different body or for another customer (details.external_id, details.existing_id); IDEMPOTENCY_IN_PROGRESS — a request with this key is still running (details.key).

    Error format and codes

  • 422

    VALIDATION_FAILED — details.fields: account_kind, amount, reason, external_id, customer, Idempotency-Key; INSUFFICIENT_BALANCE — details.account_kind, details.balance, details.requested (decimals as strings with the kind's scale); IDEMPOTENCY_MISMATCH — the key was already used for another request (details.key).

    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

Reverse an entry

POST/ledger-entries/{id}/reverse

A reversal is a reversal entry for the same amount with the opposite sign, one per original entry. Ability ledgers:write; the Idempotency-Key header is required. It bypasses the negative-balance ban and works for a disabled kind and for a customer in any status: a reversal corrects an error. The entry is not in the organization or is bound to an interaction outside the projects assigned to the API client — NOT_FOUND. A reversing entry and an interaction entry (redemption, accrual — only voiding the interaction cancels them) cannot be reversed separately — CONFLICT with details.entry_id and details.kind; an erroneous reversal is corrected with a new manual entry. reason — 1–1000 characters.

Response 201 — the reversing entry and meta.balance — the kind's balance after it. A repeated reversal — 200 with the same reversing entry (the first reason) and meta.idempotent_replay: true.

Parameters

  • idstring (uuid)pathrequired

  • Idempotency-Keystringheaderrequired

    Idempotency key: unique within the client, lives for 24 hours. A repeat with the same key and request returns the saved response with meta.idempotent_replay: true; a different request with the same key gets IDEMPOTENCY_MISMATCH. A UUID is recommended.
    Constraints
    minLength: 1maxLength: 255

Request body

application/json

VoidInput

Void body
  • reasonstringrequired

    Human-readable reason, may be multiline
    Constraints
    minLength: 1maxLength: 1000

Responses

  • 200

    The entry was already reversed — the same reversing entry, meta.idempotent_replay

    application/json

    LedgerEntryResponse

    • dataLedgerEntryrequired

    • metaobjectrequired

      Service data of the response; for lists it contains cursor
      Fields
      • 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

      • balanceCustomerBalancerequired

  • 201

    Reversing entry recorded

    application/json

    LedgerEntryResponse

    • dataLedgerEntryrequired

    • metaobjectrequired

      Service data of the response; for lists it contains cursor
      Fields
      • 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

      • balanceCustomerBalancerequired

  • 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 — resource or route not found

    Error format and codes

  • 409

    CONFLICT — a reversing entry or an interaction entry (details.entry_id, details.kind); IDEMPOTENCY_IN_PROGRESS — a request with this key is still running (details.key).

    Error format and codes

  • 422

    VALIDATION_FAILED — details.fields: reason, Idempotency-Key; IDEMPOTENCY_MISMATCH — the key was already used for another request (details.key).

    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

LedgerEntry

object

A ledger entry on a customer account. Entries are only appended, never changed or deleted. The amount is signed: plus is an accrual, minus is a redemption. reversal_id is the offsetting entry if this one was reversed (one reversal per entry).
  • idstring (uuid)required

  • account_kindstringrequired

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

  • amountstringrequired

    Signed amount — a decimal as a string with exactly the kind's number of decimal places (scale); for a kind with corrupted settings — the canonical form without trailing zeros
    Example
    100-40.00
  • reasonstring | nullrequired

    Reason; accrual has none — the decision row gives the reason
  • interaction_idstring (uuid) | nullrequired

    The interaction for redemption, accrual, their offsetting entries, and the transfer pair that moves the offsetting entries of a merged customer's interaction void to the primary customer
  • decision_row_idstring (uuid) | nullrequired

    Decision table row for accrual
  • reverses_entry_idstring (uuid) | nullrequired

    The entry being reversed, for reversal
  • reversal_idstring (uuid) | nullrequired

    The offsetting entry if this one was reversed
  • external_idstring | nullrequired

    The API client's natural key, for manual
  • actorActorrequired

  • created_atstring (date-time)required

    ISO 8601, UTC, to the second

LedgerEntryKind

string

Entry kind (closed list): manual — manual (API, customer card), redemption — a spend in an interaction request, accrual — an award by the account kind's decision table, reversal — the offsetting reversal entry, transfer — a balance transfer on a customer merge: a pair with an offsetting entry, minus on the absorbed customer, plus on the primary, without a cause, not reversible; in the entry list and timeline of the primary the pairs within the group “primary and those merged into it” are not returned, entries of merged customers are
Values
manualredemptionaccrualreversaltransfer

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

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

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