Data model
This page covers the entities your server works with and how they connect. In the diagram, blue is what we set up, green is what your server sends, and orange is what Zirva computes.
Overview
Section titled “Overview”flowchart LR user["User<br/>user_ref, attributes"] --> event["Event<br/>event_id, type"] event --> prog["Progress<br/>per scenario"] prog --> comp["Completion"] comp --> reward["Reward<br/>discount"] comp --> badge["Badge"] dict["Event dictionary"] -.-> event scen["Scenario<br/>steps, window, levels"] -.-> prog tmpl["Reward template"] -.-> reward cat["Badge catalog"] -.-> badge classDef ours fill:#e7efff,stroke:#4a6cf7,color:#1b1f3b classDef yours fill:#e6f6ec,stroke:#2f9e5b,color:#13301f classDef engine fill:#fff3e0,stroke:#e08a1e,color:#3b2508 class dict,scen,tmpl,cat ours class user,event yours class prog,comp,reward,badge engine
In short: an event is described in the dictionary and belongs to a user. The engine applies scenario rules to it and moves progress forward. When the steps are done, a completion appears, and with it a reward from the template and, if configured, a badge.
Entities
Section titled “Entities”A person on your site. You choose their user_ref: Latin letters, digits and _ . : -, up to 128 characters. Do not use an email or a phone number.
| Field | What it is |
|---|---|
user_ref |
your internal user ID |
attributes |
attributes for scenario audiences, for example seller_type: private |
group |
participant or control: whether the user takes part in the program right now |
You don’t have to create a user in advance: the first event creates them. More in Users and the control group.
A fact about what a user did. Four fields are required; the rest depend on the event type in your dictionary.
| Field | What it is |
|---|---|
event_id |
your unique event ID; we drop duplicates by it |
type |
a type from the dictionary, for example order.paid or listing.published |
user_ref |
whose event it is |
occurred_at |
when it happened, RFC 3339 with a time zone |
order_id, amount, currency, items, … |
type fields: link key, amount, items, object |
Rollbacks (order.refunded, order.chargeback, listing.rejected) are events too: they point to the original event by its link key (order_id, listing.id) and roll progress back.
Scenario
Section titled “Scenario”A rule for “what to do”. We set its steps, window, levels and audience; you see the scenario in the user’s status.
| Part | What it is | Example |
|---|---|---|
| Steps | which event, how to count, how many | 3 × order.paid from 10 AZN |
| Step metric | count, sum, distinct_days, distinct_weeks, consecutive_weeks, distinct_values |
count |
| Window | sliding (any N days) or from_first_event (N days from the first event) |
any 60 days |
| Levels | tiers within a scenario, each with its own reward | bronze, silver, gold |
| Object | count separately for each listing or order | listing L-552918 |
| Audience | who it is for, by attributes | private sellers only |
| Version | editing a scenario creates a new version | version: 2 |
Reward
Section titled “Reward”A discount issued to a user. Your site creates the coupon for it, and we keep track of its status.
| Field | What it is |
|---|---|
reward_id |
the reward ID; create exactly one coupon per ID |
status |
pending, available, reserved, redeemed, expired, cancelled |
percent or amount |
discount size |
max_amount, min_order |
discount cap and minimum order amount |
applies_to, applies_to_ref |
what it applies to: a category or a paid service, sometimes a specific object |
available_at, expires_at |
when it becomes available and when it expires |
scenario |
what it was issued for: scenario, version, level, object, completion ID |
An achievement mark in the profile. A badge stays while at least one valid completion grants it: if a refund cancels the completion, the badge is revoked (badge.revoked). Public badges can be shown to other users via GET /v1/badges.
Reward lifecycle
Section titled “Reward lifecycle”stateDiagram-v2 direction LR [*] --> pending: scenario completed pending --> available: available_at reached available --> pending: recalculation moved the completion available --> reserved: reserve reserved --> available: release or reservation expired reserved --> redeemed: redeem with the same order_id available --> redeemed: redeem without a reservation available --> expired: expires_at reached reserved --> expired: term ended during the reservation pending --> cancelled: rollback or operator available --> cancelled: rollback or operator reserved --> cancelled: rollback redeemed --> [*] expired --> [*] cancelled --> [*]
Webhooks are sent for transitions to available, expired and cancelled. Your server makes reservations, redemptions and releases itself, so there are no webhooks for them.
Event lifecycle
Section titled “Event lifecycle”stateDiagram-v2 direction LR [*] --> accepted: 202 on POST /v1/events accepted --> processed: counted in at least one scenario accepted --> ignored: counted nowhere, reason in reason processed --> ignored: a refund arrived later ignored --> processed: the refund was reversed
GET /v1/events/{event_id} shows the event’s state. Recalculation covers all of the user’s events, so the state can change later, for example when a refund arrives.
Who does what
Section titled “Who does what”sequenceDiagram
autonumber
participant B as Buyer
participant S as Your server
participant A as Zirva
B->>S: pays for an order
S->>A: POST /v1/events (order.paid)
A-->>S: 202 accepted
Note over A: background recalculation:<br/>progress, completion, reward
A->>S: webhook reward.available
S->>A: GET /v1/rewards/{reward_id}
A-->>S: discount terms
S->>S: create a coupon (one per reward_id)
B->>S: checks out the next order
S->>A: POST /v1/rewards/{reward_id}/reserve
A-->>S: 200 reserved
B->>S: pays with the discount
S->>A: POST /v1/rewards/{reward_id}/redeem
A-->>S: 200 redeemed
See it with real requests and responses in the end-to-end example.