Skip to content

Introduction

Storelayer holds loyalty state and runs loyalty logic for your application. Your backend stays the source of truth for orders and customers; it tells Storelayer what happened (events), asks what a cart is worth (promotions), and reads or moves balances (wallets).

PrimitiveWhat it isYou interact by…
ProjectThe boundary for all config, rules, promotions, customers, and keysOne API key per integration, scoped to one project
Customer (external user)Your customer, identified by your stable ID (userId)POST /projects/{projectId}/users
EventSomething that happened: { type, userId, payload }POST /ingest/events
RuleConditions over the event + actions to run when they matchPOST /projects/{projectId}/rules
WalletPer-customer balances, one per asset type (points, stamps, …)GET /projects/{projectId}/users/{userId}/wallet
PromotionCart-level discount logic, optionally behind couponsPOST /projects/{projectId}/promotions/evaluate
ReferralCodes, referrer/referee attribution, and completionReferrals endpoints
WorkflowThe recorded run of one event through your rulesWorkflows endpoints

Earning (asynchronous):

your backend ──POST /ingest/events──▶ event accepted (201, id evt_…)
│ queued
▼
active rules evaluated
(conditions on $('event').payload…)
│ match
▼
actions: reward → wallet earn,
modify, integration, emit_event, …
│
▼
workflow run recorded

Ingesting returns before rules run. Never read the wallet immediately after sending an event and assume the reward is there — inspect the workflow run or poll the balance. See workflows.

Discounting (synchronous): send the cart to POST /projects/{projectId}/promotions/evaluate; the response contains the qualifying promotions and per-item discounts. Cart money is integer minor units ($25.00 = 2500). See creating promotions.

Referring: a referrer gets a code, a referee applies it, and a later event (for example a first purchase) completes the referral and rewards both sides through rule actions. See referral programs.

Direct wallet writes: when your backend already decided the outcome (customer-service credit, migration from another system), call the wallet endpoints (earn, spend, modify) directly instead of going through an event and rule.

Choosing between an event and a direct wallet call

Section titled “Choosing between an event and a direct wallet call”
Use an event + rule when…Use a direct wallet call when…
Marketing or ops should change the reward without a deployThe amount is computed by your backend and fixed
One business fact can trigger several outcomes (points, referral completion, webhook)You need the new balance in the same request
You want a recorded, replayable decision per eventIt is a one-off adjustment or import

Use one stable customer ID everywhere — events, wallets, referrals, carts. Wallets are keyed by project + userId; a different spelling of the same customer is a different wallet. Register customers with POST /projects/{projectId}/users before using their ID; wallet calls do not check registration.

Append .md to any page path for its Markdown source (for example /concepts/wallets.md); /llms.txt indexes all pages.