Referrals
Current user's referral code + redemption of another user's code.
Each user gets their own code lazily (first read creates it). Rewards are paid server-side on claim — both reward_referrer and reward_referee are honored, clamped to any currency max_balance, and logged to currency_transactions under source = 'referral'.
Source: apps/api/src/routes/client/referrals.ts.
Endpoints
| Method | Path | Description |
|---|---|---|
| GET | /client/referrals/my-code | Get (or lazily create) the caller's referral code. |
| POST | /client/referrals/claim | Claim someone else's code. |
GET /client/referrals/my-code
If the user already has a code, returns it. Otherwise a new code is generated (with up to 5 retries on 23505 unique_violation). Rewards are copied from the first admin-created template code (app_user_id IS NULL) if one exists.
Response 200 (existing) / 201 (newly created)
Errors
500 RETRY_EXHAUSTED— could not generate a unique code after 5 attempts.500 CREATE_FAILED.
Try it:
/client/referrals/my-codecurl -X GET 'https://api.amba.dev/client/referrals/my-code'Curl:
POST /client/referrals/claim
All validation + the referral_claims insert + the current_uses increment run under FOR UPDATE on the code row so concurrent claims serialize. Reward grants run post-commit as best-effort — a grant failure is logged but the claim succeeds (operators reconcile from currency_transactions).
Request
| Field | Type | Required |
|---|---|---|
code | string | yes |
Response 201
Errors
400 SELF_REFERRAL— the code belongs to the caller.400 MAX_USES_REACHED— code hit its use cap.400 ALREADY_CLAIMED— caller has already claimed this code.404 INVALID_CODE— code not found or inactive.500 CLAIM_FAILED.
Try it:
/client/referrals/claimcurl -X POST 'https://api.amba.dev/client/referrals/claim'Curl: