HTTP API Reference

Base URL: https://gameplaygen.com/api/economy

All endpoints (except game creation) require a Bearer token: Authorization: Bearer <api_key>

Endpoints Overview

Core
POST/gamesCreate a game (no auth)
POST/currenciesDefine a currency
POST/itemsDefine an item
POST/playersGet or create a player
POST/players/batchCreate up to 100 players at once
POST/grantGrant currency to player
POST/spendSpend currency from player
POST/purchaseBuy an item (atomic)
POST/transferTransfer currency between players
GET/statsEconomy statistics
GET/configGame economy config
GET/transactionsPaginated transaction log
GET/players/:id/balancePlayer balances
GET/players/:id/inventoryPlayer inventory
Advanced
POST/craftCraft a recipe
POST/loot/rollRoll a loot table
POST/marketplace/listList item for sale
POST/marketplace/buyBuy a marketplace listing
GET/audit-flagsAnti-cheat audit flags

Response Format

All responses follow a consistent envelope:

json
// Success
{
  "success": true,
  "data": { ... },
  "requestId": "req_a1b2c3d4e5f6"
}

// Error
{
  "success": false,
  "error": "Missing required field: currencyId",
  "requestId": "req_a1b2c3d4e5f6"
}

POST /games

Create a new game. No authentication required. Returns an API key — store it securely.

FieldTypeRequiredDescription
namestringYesUnique game name
ownerIdstringNoOwner identifier (default: anonymous)
bash
curl -X POST https://gameplaygen.com/api/economy/games \
  -H "Content-Type: application/json" \
  -d '{ "name": "my-game" }'
json
{
  "success": true,
  "data": {
    "gameId": "j97abc...",
    "apiKey": "gg_live_sk_abc123..."
  }
}

POST /currencies

Define a currency. Idempotent — updates if it already exists.

FieldTypeRequiredDescription
currencyIdstringYesUnique currency identifier (e.g. gold, gems)
namestringYesDisplay name
iconstringYesEmoji or icon URL
maxBalancenumberNoMaximum balance cap per player
bash
curl -X POST https://gameplaygen.com/api/economy/currencies \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{ "currencyId": "gold", "name": "Gold", "icon": "💰" }'

POST /items

Define a purchasable item with pricing.

FieldTypeRequiredDescription
itemIdstringYesUnique item identifier
namestringYesDisplay name
raritystringNoRarity tier
prices{ currencyId, amount }[]YesPrice list
maxOwnednumberNoMax quantity per player
metadataobjectNoCustom metadata
bash
curl -X POST https://gameplaygen.com/api/economy/items \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "itemId": "iron-sword",
    "name": "Iron Sword",
    "rarity": "common",
    "prices": [{ "currencyId": "gold", "amount": 50 }]
  }'

POST /players

Get or create a player by external ID. Idempotent.

FieldTypeRequiredDescription
externalIdstringYesYour user/player ID
metadataobjectNoCustom player metadata
bash
curl -X POST https://gameplaygen.com/api/economy/players \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{ "externalId": "player_42" }'

POST /players/batch

Create up to 100 players in a single request. Each player can have initial wallet balances. Ideal for game setup, migrations, or simulations.

FieldTypeRequiredDescription
playersarrayYesArray of player objects (max 100)
players[].externalIdstringYesYour user/player ID
players[].displayNamestringNoDisplay name (defaults to externalId)
players[].walletsarrayNoInitial wallet balances: [{ currencyId, balance }]
bash
curl -X POST https://gameplaygen.com/api/economy/players/batch \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "players": [
      { "externalId": "player_1", "displayName": "Alice", "wallets": [{ "currencyId": "gold", "balance": 100 }] },
      { "externalId": "player_2", "displayName": "Bob", "wallets": [{ "currencyId": "gold", "balance": 50 }] }
    ]
  }'

Returns { success: true, players: [{ externalId, playerId }, ...] }

POST /grant

Grant (mint) currency to a player. This is a faucet — it creates new currency.

FieldTypeRequiredDescription
externalIdstringYes*Player external ID (preferred)
playerIdstringYes*Internal player ID (legacy)
currencyIdstringYesCurrency to grant
amountnumberYesAmount to grant (positive)
metadataobjectNoe.g. { reason: 'quest_complete' }
idempotencyKeystringNoUnique key to prevent duplicate grants

* Provide either externalId or playerId.

bash
curl -X POST https://gameplaygen.com/api/economy/grant \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "externalId": "player_42",
    "currencyId": "gold",
    "amount": 100,
    "metadata": { "reason": "quest_complete" }
  }'

POST /spend

Deduct currency from a player. Fails if insufficient balance.

FieldTypeRequiredDescription
externalIdstringYes*Player external ID
currencyIdstringYesCurrency to spend
amountnumberYesAmount to deduct
metadataobjectNoe.g. { reason: 'repair_cost' }
idempotencyKeystringNoUnique key to prevent duplicates
bash
curl -X POST https://gameplaygen.com/api/economy/spend \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "externalId": "player_42",
    "currencyId": "gold",
    "amount": 30
  }'

POST /purchase

Atomic item purchase — deducts the item's price and adds it to the player's inventory. Rolls back if anything fails.

FieldTypeRequiredDescription
externalIdstringYes*Player external ID
itemIdstringYesItem to purchase
metadataobjectNoCustom metadata
bash
curl -X POST https://gameplaygen.com/api/economy/purchase \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{ "externalId": "player_42", "itemId": "iron-sword" }'

POST /transfer

Transfer currency between two players. Subject to anti-cheat laundering detection.

FieldTypeRequiredDescription
fromExternalIdstringYesSender player external ID
toExternalIdstringYesRecipient player external ID
currencyIdstringYesCurrency to transfer
amountnumberYesAmount to transfer
metadataobjectNoCustom metadata
bash
curl -X POST https://gameplaygen.com/api/economy/transfer \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "fromExternalId": "player_42",
    "toExternalId": "player_99",
    "currencyId": "gold",
    "amount": 50
  }'

GET /stats

Economy-wide statistics including player count, transaction totals, and currency flows.

bash
curl https://gameplaygen.com/api/economy/stats \
  -H "Authorization: Bearer gg_live_sk_..."
json
{
  "success": true,
  "data": {
    "totalPlayers": 1247,
    "totalTransactions": 89432,
    "currencyStats": [{
      "currencyId": "gold",
      "totalInCirculation": 5430000,
      "totalGranted": 8200000,
      "totalSpent": 2770000
    }]
  }
}

GET /config

Returns the game's economy configuration — all defined currencies and items.

bash
curl https://gameplaygen.com/api/economy/config \
  -H "Authorization: Bearer gg_live_sk_..."

GET /transactions

Paginated transaction log.

ParamTypeDescription
limitnumberResults per page (default 50)
cursorstringPagination cursor from previous response
bash
curl "https://gameplaygen.com/api/economy/transactions?limit=20" \
  -H "Authorization: Bearer gg_live_sk_..."

GET /players/:id/balance

Get all currency balances for a player.

bash
curl https://gameplaygen.com/api/economy/players/j97abc.../balance \
  -H "Authorization: Bearer gg_live_sk_..."
json
{
  "success": true,
  "data": { "gold": 750, "gems": 12 }
}

GET /players/:id/inventory

Get all items in a player's inventory.

bash
curl https://gameplaygen.com/api/economy/players/j97abc.../inventory \
  -H "Authorization: Bearer gg_live_sk_..."
json
{
  "success": true,
  "data": [
    { "itemId": "iron-sword", "quantity": 1 },
    { "itemId": "health-potion", "quantity": 5 }
  ]
}

Advanced Endpoints

POST /craft

Execute a crafting recipe — consumes ingredients and grants outputs. See Crafting docs for recipe setup.

FieldTypeRequiredDescription
gameIdstringYesGame ID
playerIdstringYesInternal player ID
recipeIdstringYesRecipe identifier
bash
curl -X POST https://gameplaygen.com/api/economy/craft \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "gameId": "j97abc...",
    "playerId": "j97def...",
    "recipeId": "iron_sword_recipe"
  }'
json
{
  "success": true,
  "data": {
    "granted": [
      { "type": "item", "id": "iron-sword", "amount": 1 }
    ]
  }
}

POST /loot/roll

Roll a loot table and grant results to a player. See Loot Tables docs.

FieldTypeRequiredDescription
gameIdstringYesGame ID
playerIdstringYesInternal player ID
tableIdstringYesLoot table identifier
bash
curl -X POST https://gameplaygen.com/api/economy/loot/roll \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "gameId": "j97abc...",
    "playerId": "j97def...",
    "tableId": "boss_dragon_table"
  }'
json
{
  "success": true,
  "data": {
    "results": [
      { "type": "item", "id": "dragon_scale", "amount": 1 },
      { "type": "currency", "id": "gold", "amount": 250 }
    ]
  }
}

POST /marketplace/list

List an item for sale on the player marketplace. The item is escrowed (removed from seller's inventory). See Marketplace docs.

FieldTypeRequiredDescription
gameIdstringYesGame ID
playerIdstringYesSeller player ID
itemIdstringYesItem to list
currencyIdstringYesCurrency for the price
pricenumberYesListing price
quantitynumberNoQuantity (default 1)
expiresAtnumberNoExpiration timestamp (ms)
bash
curl -X POST https://gameplaygen.com/api/economy/marketplace/list \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "gameId": "j97abc...",
    "playerId": "j97def...",
    "itemId": "iron-sword",
    "currencyId": "gold",
    "price": 500
  }'

POST /marketplace/buy

Buy a marketplace listing. Deducts currency from buyer, pays seller (minus tax), transfers item.

FieldTypeRequiredDescription
gameIdstringYesGame ID
playerIdstringYesBuyer player ID
listingIdstringYesListing to purchase
bash
curl -X POST https://gameplaygen.com/api/economy/marketplace/buy \
  -H "Authorization: Bearer gg_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "gameId": "j97abc...",
    "playerId": "j97ghi...",
    "listingId": "j97listing..."
  }'
json
{
  "success": true,
  "data": {
    "taxAmount": 25,
    "sellerReceives": 475
  }
}

GET /audit-flags

Get anti-cheat audit flags for your game. See Anti-Cheat docs.

ParamTypeDescription
severitystringFilter by 'warning' or 'critical'
limitnumberResults per page (default 50)
bash
curl "https://gameplaygen.com/api/economy/audit-flags?severity=warning" \
  -H "Authorization: Bearer gg_live_sk_..."
json
{
  "success": true,
  "data": [
    {
      "severity": "warning",
      "reason": "Possible laundering: 6 transfers with same player in 1 minute",
      "playerId": "j97def...",
      "resolved": false,
      "createdAt": 1708700000000
    }
  ]
}

Error Codes

StatusMeaning
400Missing or invalid request fields
401Missing or invalid API key
404Player, currency, or item not found
422Validation failed (e.g. insufficient balance, recipe on cooldown)
429Rate limited (anti-cheat)
500Internal error