API · Catalogs and rules

Agents

The registry of agents (the organization's employees and partners) and checking their codes.

Agent registry

GET/agents

A page of the organization's agent registry (the registry master is the organization's accounting system): by external ID in byte order (B < a < Я), disabled agents included; cursor pagination: pass meta.cursor.next as the cursor parameter with the same filters until it becomes null. Ability agents:read. Projects play no part. Filters combine with AND: role — role code (an unknown role gives an empty list, a malformed code is an error); group — exact equality after the same trimming and NFC as on write (a group that is empty after trimming means no filter); active — true|false|1|0, case-insensitive. An empty parameter value means no filter. Errors — VALIDATION_FAILED with details.fields.<parameter>: first the request shape (a parameter outside the list — “Unknown parameter”), then the values, all at once (role, group, activity, limit range); the cursor is checked only when the other parameters are valid.

Parameters

  • rolestringquery

    Example
    promoter
  • groupstringquery

  • activestringquery

    Example
    false
  • 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 agents

    application/json

    object

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

  • 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

Agent by external ID

GET/agents/{external_id}

A registry agent by external ID, including a disabled one (is_active: false). Ability agents:read.

Parameters

  • external_idstringpathrequired

    External ID of the agent (1–64 characters without whitespace, control characters and /, edges are trimmed, case-sensitive). If the organization has no such agent or the ID fails the format — NOT_FOUND with details.external_id as sent (first 64 characters).
    Example
    A-17

Responses

  • 200

    Agent

    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 agent with this external ID, or the ID does not match the format (details.external_id — as in the path, the first 64 characters)

    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

Create or update an agent

PUT/agents/{external_id}

Partial upsert of an agent by external ID (the registry master is the organization's accounting system). Ability agents:write. No Idempotency-Key: repeating the same body changes nothing (meta.outcome: unchanged). A body with full_name and role creates a new agent (is_active defaults to true); for an existing agent only the keys sent are changed, null clears group and a schema field ({"attributes": {"<code>": null}}). Disabling — {"is_active": false}; there is no deletion. An empty string also becomes null (for full_name and role — “Required.”). Fields of the agent schema hidden from the API are “Unknown field” in the body and are kept on update; a required field hidden from the API is not required when creating through the API.

A registry change recalculates labels of rules with an agent_registry leaf for the affected customers in the same transaction, by the old and new values of the agent's slots; the response has no effects (meta.effects is absent), the labels are visible on customer cards. A recalculation failure rolls back the upsert — INTERNAL (500), the agent is not written.

Errors — VALIDATION_FAILED with details.fields, in stages: body shape (not a JSON object — body) → the external ID from the path (external_id: 1–64 characters without whitespace and control characters, not dots only, not starting with a combining mark; / (%2F) and an empty ID are cut off by the router — NOT_FOUND) → everything else at once: an unknown key, full_name, role (an unknown or disabled role; an unchanged role is not re-checked), group, is_active, attributes (not an object; [] equals {}), attributes.<code> (field value, slot normalization), codes (not a list, more than 100), codes.<i> (not an object), codes.<i>.<key> (code, duplicate, taken by another agent, validity period, activity), codes.<i>.parameters.<key>.

Personal codes (codes) are written in the same transaction; if only the codes changed — meta.outcome: updated, while the agent's updated_at stays the same (a code has its own). Rules do not read codes, so codes do not trigger label recalculation.

Parameters

  • external_idstringpathrequired

    External ID of the agent: 1–64 characters without whitespace, control characters and /, edges are trimmed, NFC, case-sensitive. A value that fails the format — VALIDATION_FAILED under external_id (for reading — NOT_FOUND); / (%2F) and an empty ID are a different path, the router's NOT_FOUND.
    Example
    A-17

Request body

application/json

AgentUpsert

Agent upsert body — only the keys sent; a missing key means “leave as is” (for a new agent — empty or the default). A key outside the list — “Unknown key”.
  • full_namestring

    Full name; edges are trimmed (whitespace, invisible, control characters), NFC; required for a new agent
    Constraints
    maxLength: 255
  • rolestring

    Code of an active agent role (type agent_role); required for a new agent
    Example
    promoter
  • groupstring | null

    Group; null or empty after trimming — no group
    Constraints
    maxLength: 255
  • is_activeboolean

    false disables the agent; true by default for a new agent
  • attributesobject

    Fields of the agent schema visible to the API, under their codes; a field on the phone slot is normalized to E.164 by the field's region, on the national_id slot — by the identity type; null clears an optional field.
  • codesarray<AgentCodeUpsert>

    Personal codes ({} is the same as []) — merged by code: a code the agent does not have is created, an existing one gets the sent item keys changed; the agent's codes missing from the list do not change; no codes key — codes are left alone. There is no deletion — disable with is_active: false. The same code twice in the list (including in a different case) — “Duplicate code”; a code of another agent of the organization (even a disabled one) — “already taken”: a code is unique within the organization and does not move to another agent.
    Constraints
    maxItems: 100

No other keys

Responses

  • 200

    Agent updated or unchanged

    application/json

    AgentUpsertResponse

    • dataAgentrequired

    • 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

      • outcomestringrequired

        Upsert outcome; created — with status 201
        Values
        createdupdatedunchanged
  • 201

    Agent created

    application/json

    AgentUpsertResponse

    • dataAgentrequired

    • 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

      • outcomestringrequired

        Upsert outcome; created — with status 201
        Values
        createdupdatedunchanged
  • 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

  • 500

    INTERNAL — the agent rule recalculation failed, or another error; the upsert is rolled back

    Error format and codes

Check an agent's personal code

POST/agent-codes/validate

Whether an agent's personal code is valid at moment. Ability agent-codes:validate, separate from agents:read: the check does not open the registry with phone numbers and national identifiers. Projects play no part; codes are shared across the organization. The check writes nothing: the response is 200 even on refusal — valid: false with the reason in reason. No Idempotency-Key.

The code is compared case-insensitively (ref-31ab is the same code as REF-31AB), edges are trimmed; a code that fails the format (not Latin letters, digits, -, _; longer than 64) is unknown, not an error. Reasons — the first that applies, in order: unknown (no such code in the organization) → inactive (the code is disabled) → agent_inactive (the agent is disabled) → not_started (moment is before valid_from) → expired (moment is not before valid_to). The CRM does not interpret code parameters and returns them as is; parameters and the agent are returned only for a valid code.

Request body

application/json

object

Extra key — VALIDATION_FAILED under its name; a list body — under body
  • codestring | nullrequired

    The code as a string; empty, whitespace only or null — unknown. A missing key or a non-string (including a number) — VALIDATION_FAILED under code.
    Constraints
    maxLength: 255
    Example
    ref-31ab
  • momentstring (date-time)

    Moment of the check (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

    Check result (also on refusal)

    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

  • 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

Agent

object

Agent in the organization's registry: a person in the organization's programme (promoter, employee, salesperson) — not an admin panel user and not an API client. The key is the external ID from the organization's records system; the internal id is not exposed.
  • external_idstringrequired

    External ID — no whitespace, control characters or /, case-sensitive
    Constraints
    minLength: 1maxLength: 64
    Example
    A-17
  • full_namestringrequired

    Constraints
    maxLength: 255
  • rolestringrequired

    Agent role code — type agent_role (GET /v1/schema/agent, types)
    Example
    promoter
  • groupstring | nullrequired

    Group for filtering; null — no group
    Constraints
    maxLength: 255
  • is_activebooleanrequired

    A disabled agent does not take part in matching with customers (the agent_registry rule leaf)
  • attributesobjectrequired

    Each active field of the agent schema visible to the API, under its code, in schema order; a field on a slot (phone, national_id) — the normalized value (phone — E.164); not set — null.
  • codesarray<AgentCode>required

    The agent's personal codes ordered by code bytewise, including disabled ones; [] — none
  • created_atstring (date-time)required

  • updated_atstring (date-time)required

AgentCode

object

Personal agent code: the CRM does not interpret the parameters, POST /v1/agent-codes/validate returns them as is. Validity is [valid_from, valid_to) in UTC to the second: at valid_to the code is no longer valid.
  • codestringrequired

    Code in canonical upper case
    Constraints
    pattern: ^[A-Z0-9_-]{1,64}$
    Example
    REF-31AB
  • valid_fromstring (date-time) | nullrequired

    Start of validity; null — no start
  • valid_tostring (date-time) | nullrequired

    End of validity (exclusive); null — no expiry
  • parametersAgentCodeParametersrequired

  • is_activebooleanrequired

    A disabled code is rejected by validate with reason inactive
  • created_atstring (date-time)required

  • updated_atstring (date-time)required

AgentCodeParameters

object

Flat “key → scalar” object: a key is lowercase Latin letters, digits and single _, starting with a letter (any other form, such as Discount, is an error, not converted); a value is a string up to 255 characters without control characters, a finite number or true/false; null, an object and a list are errors. An integer with a .0 fraction is returned as an integer.
Constraints
maxProperties: 32
Example
{"discount":2000,"kind":"fixed"}

Key values: string | number | boolean

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

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

AgentCodeUpsert

object

Item of codes in an agent upsert — only the keys sent: a new code gets valid_from and valid_to set to null, parameters to {}, is_active to true. An empty string becomes null (for valid_* it clears the validity bound, for code — “Required.”); parameters are taken as sent, without trimming or replacing "". An item [] is parsed as an empty object. Errors are under codes.<i>, codes.<i>.<key>, codes.<i>.parameters.<key>; a key outside the list — “Unknown key”.
  • codestringrequired

    Latin letters, digits, - and _, 1–64 after trimming the edges (whitespace, invisible characters); case-insensitive — stored in upper case
    Example
    ref-31ab
  • valid_fromstring (date-time) | null

    RFC 3339 with a time zone; fractions of a second are dropped; null — no start
  • valid_tostring (date-time) | null

    RFC 3339 with a time zone, later than valid_from; may be in the past; null — no expiry
  • parametersAgentCodeParameters

  • is_activeboolean

No other keys

AgentCodeCheck

object

  • codestringrequired

    Code in canonical upper case; for a code that fails the format — as sent, with edges trimmed (empty — "")
  • momentstring (date-time)required

    Check moment in UTC to the second
  • validbooleanrequired

  • reasonAgentCodeReason | nullrequired

    null — the code is valid
  • valid_fromstring (date-time) | nullrequired

    Start of validity of a known code; null for unknown and with no start
  • valid_tostring (date-time) | nullrequired

    End of validity of a known code (exclusive); null for unknown and with no expiry
  • parametersAgentCodeParameters | nullrequired

    Parameters — only when valid: true
  • agentAgentBrief | nullrequired

    Agent — only when valid: true

AgentCodeReason

string

Why the code is not valid, in check order: unknown — no such code (or it fails the format), inactive — the code is disabled, agent_inactive — the agent is disabled, not_started — validity has not started yet, expired — validity has ended
Values
unknowninactiveagent_inactivenot_startedexpired

AgentBrief

object

Agent of a valid code — without schema fields (phone, national ID) and without codes
  • external_idstringrequired

  • full_namestringrequired

  • rolestringrequired

  • groupstring | nullrequired