- 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)
amount_okassertplayerread collection economy_balancecan_affordconditiontakewrite 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