Read-only demo.Generated sample data. Changes cannot be saved.

economy_spend

economy_spend POST YAML steps Enabled Public

Calls this month
0
Errors
0
Error rate
No calls yet
Avg response
No calls yet

This month, UTC.

Definition preview

Read-only outline of the saved source. Edit it under the Edit tab.

Input fields

amount
number

Pipeline (4)

  1. amount_ok assert
  2. player read collection economy_balance
  3. can_afford condition
  4. take write collection economy_balance

Response

Status
200
Body
keys: success, spent
Full source
sourceVersion: 1
kind: endpoint
id: economy_spend
name: Spend gold
description: Removes gold after checking the balance on the server. Fails with INSUFFICIENT_FUNDS instead of going negative.
method: POST
enabled: true
input:
  type: object
  properties:
    amount:
      type: number
  required:
  - amount
steps:
- id: amount_ok
  type: assert
  check:
    all:
    - field: input.amount
      op: '>'
      value: 0
    - field: input.amount
      op: <=
      value: '{{values.economy_limits.max_spend_per_call}}'
  status: 422
  errorCode: INVALID_AMOUNT
  message: Amount must be between 1 and the per-call limit.
- id: player
  type: read
  collection: economy_balance
  key: '{{steamId}}'
- id: can_afford
  type: condition
  check:
    field: player.gold|0
    op: '>='
    value: '{{input.amount}}'
  onFail:
    status: 409
    error: INSUFFICIENT_FUNDS
    message: Not enough gold to spend {{input.amount}}.
- id: take
  type: write
  collection: economy_balance
  key: '{{steamId}}'
  ops:
  - op: inc
    path: gold
    valueExpression: 0 - {{input.amount}}
    source: spend
    reason: Spent gold
response:
  status: 200
  body:
    success: true
    spent: '{{input.amount}}'
module: economy

New endpoint

Choose an id using letters, numbers, underscore or hyphen. A fresh draft opens with this id; nothing is published until you save.

Confirm