Currencies
Virtual currency definitions, admin grants, per-user transaction history.
Currencies are named tokens (code like "gems") with optional cap (max_balance) and auto-recharge rules. user_balances holds per-user state. Grants are performed atomically under a FOR UPDATE row lock with a pre-flight zero-row insert so first-time grants can't race.
Source: apps/api/src/routes/admin/currencies.ts.
Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /admin/projects/:projectId/currencies | Create a currency definition. |
| GET | /admin/projects/:projectId/currencies | List currency definitions. |
| PATCH | /admin/projects/:projectId/currencies/:currencyId | Partial update. |
| DELETE | /admin/projects/:projectId/currencies/:currencyId | Delete. |
| POST | /admin/projects/:projectId/currencies/grant | Grant currency to a user (admin source). |
| GET | /admin/projects/:projectId/currencies/transactions/:userId | Paginated transaction history for a user. |
POST /admin/projects/:projectId/currencies
Request
| Field | Type | Required | Default |
|---|---|---|---|
code | string | yes | — |
name | string | yes | — |
description | string | no | null |
is_premium | boolean | no | false |
initial_balance | number | no | 0 |
max_balance | number | no | null (uncapped) |
auto_recharge_amount | number | no | null |
auto_recharge_interval_hours | number | no | null |
Response 201
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/currenciescurl -X POST 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/currencies'Curl:
GET /admin/projects/:projectId/currencies
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/currenciescurl -X GET 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/currencies'Curl:
PATCH /admin/projects/:projectId/currencies/:currencyId
Allowed fields: name, description, is_premium, initial_balance, max_balance, auto_recharge_amount, auto_recharge_interval_hours.
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/currencies/%7B%7BcurrencyId%7D%7Dcurl -X PATCH 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/currencies/%7B%7BcurrencyId%7D%7D'Curl:
DELETE /admin/projects/:projectId/currencies/:currencyId
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/currencies/%7B%7BcurrencyId%7D%7Dcurl -X DELETE 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/currencies/%7B%7BcurrencyId%7D%7D'Curl:
POST /admin/projects/:projectId/currencies/grant
Grant currency to a user. Clamped to max_balance if set; a fully-clamped grant still returns 201 with a zero-delta currency_transactions row for auditability.
Request (GrantCurrencyInput)
| Field | Type | Required | Description |
|---|---|---|---|
app_user_id | uuid | yes | Recipient. |
currency_code | string | yes | Must exist in currency_definitions. |
amount | number | yes | Must be finite and > 0. |
reason | string | no | Free-form reference id stored on the transaction. |
Response 201
Errors
400 INVALID_AMOUNT— amount isn't a positive finite number.404 CURRENCY_NOT_FOUND— unknowncurrency_code.500 GRANT_FAILED.
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/currencies/grantcurl -X POST 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/currencies/grant'Curl:
GET /admin/projects/:projectId/currencies/transactions/:userId
Paginated transaction history for a single user, most recent first.
Query
| Param | Default |
|---|---|
limit | 50 |
offset | 0 |
Response 200
Try it:
/admin/projects/%7B%7BprojectId%7D%7D/currencies/transactions/%7B%7BuserId%7D%7Dcurl -X GET 'https://api.amba.dev/admin/projects/%7B%7BprojectId%7D%7D/currencies/transactions/%7B%7BuserId%7D%7D'Curl: