Credit balances and ledger
A customer’s credit balance says how many credits they have left in a credit currency. The credit ledger is the history behind it: every grant, spend, expiry, void, refill and overage, each with the balance after it. Use the balance to show your customer what’s left, and the ledger to explain how it got there. The ledger is append-only, so its entries always add up to the balance.
Use balances and the ledger to:
- Show what’s left in your product, with a customer’s credit balance.
- Find customers about to run out, across your whole account, with the
available[lte]andpercentAvailable[lte]filters. - Explain a balance to your customer, entry by entry, with credit transactions.
- Reconcile credits against the grants, events and orders behind them.
How balances and the ledger fit together
- Every change is a ledger entry. A grant adds credits, a spend or an expiry takes them away, and each entry records the balance after it.
- The balance is computed from the entries, per customer and credit currency:
availableisgrantedminususedminusheld. - Holds and overage sit beside the ledger. A credit hold reserves credits without writing an entry, and overage is billed in money rather than taken from the balance.
Credit amounts are in the credit currency, as exact decimal strings with up to 15 decimal places. A balance doesn’t stay a whole number once a fractional spend arrives, so don’t assume balances are integers.
Credit balances
Brightrail’s app shows each user how many Adatum credits their company has left:
API
Dashboard
List credit balances for a customer and credit currency. A balance has no ID of its own, so the list is how you read one. These endpoints are in the credits=v1 beta; send Paid-Beta: credits=v1.
In the response, available is 1,200 - 200.25 - 0 = 999.75, and percentAvailable is 999.75 ÷ 1,200 × 100 = 83.3125.
Find customers running low
Leave out customer to list balances across your account. available[lte] and percentAvailable[lte] keep only the balances at or below a value, sorted by percentAvailable, lowest first:
Customers with unlimited grants are left out, because their percentAvailable is null. To top up low balances automatically, use auto top-ups.
Child customers’ balances
With customer, set includeChildren=true to also list the balances of that customer’s child customers, one row each. Trey Research reads Northwind Traders’ balances together with those of its subsidiaries, such as Northwind UK Ltd:
Rows aren’t summed: each child keeps its own balance, and a child never spends its parent’s credits. includeChildren needs customer.
Seat balances
With holder=seat, the list returns each seat’s own balance instead of the shared ones, with seat and customerUnit set. A seat’s usage spends its own balance first, then the shared balance.
Credit transactions
Each change to a balance is a credit transaction: one entry in the ledger. List credit transactions to read them, newest first:
Each entry has a signed amount, the balanceAfter it, occurredAt (when the usage or grant happened) and createdAt (when it was recorded). It links to what caused it: the grant, event, meter, product, order or seat. Filter by type, grant, event, order, product, meter or an occurredAt range to trace a balance back to the usage behind it. reason carries a manual grant’s reason.
How it reconciles
Brightrail starts a trial with a 1,000-credit grant that expires on 1 January 2027, and gets 200 goodwill credits that never expire. Adatum charges 4 credits a minute. Here’s its first day of the ledger, oldest first:
The grant, spend, expiry, void and refill entries always sum to the balance before holds, available + held: 1,000 - 120 - 0.5 + 200 - 79.75 = 999.75. All three spends came from the trial grant, because it’s forfeited first, so nextExpiry is 1,000 - 200.25 = 799.75 credits on 1 January.
The next day, one event costs 1,019.75 credits, 254.9375 minutes × 4. The balance covers 999.75 of it:
The balance now shows available of 0 and overage of 20. At the credit currency’s 75¢ conversion, the overage is billed as 20 × 75¢ = 1,500¢, or $15.00. Overage entries are left out of the balance sum: those not yet invoiced add up to the balance’s overage.
Correct a balance
Ledger entries can’t be changed or deleted. To add credits, create a grant. To take them away, void the grant that holds them, which writes a void entry, and grant the right amount again if needed.