Admin Credits — TypeScript SDK
Read and adjust an end-customer's credit balance.
Overview
The admin Credits resource reads a customer's credit/billing balance and adjusts the customer's manually-granted (adjustable) credit amount.
Accessed via admin.credits.
Available Operations
| Method | Description |
|---|---|
getCredit() | Read a customer's credit balance summary |
setCredit() | Adjust a customer's adjustable credit amount |
getCredit
Read a customer's credit/billing balance.
Example Usage
const balance = await admin.credits.getCredit(42);
console.log(balance);
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| userId | number | Yes | -- | Target customer id (positional argument) |
Response
Returns an object with the customer's balance fields. Note that several backend field names are spelled ...Amout (rechargeAmout, refundAmout, usedAmout, otherAmout) and are returned exactly as the server sends them.
Errors
| Code | Exception | When |
|---|---|---|
2007 | PermissionError | Admin lacks Credit Management permission |
3001 | AuthenticationError | Session expired and refresh failed |
setCredit
Adjust a customer's adjustable credit amount.
Example Usage
const ok = await admin.credits.setCredit(42, 100);
console.log(ok); // true
// Reset back to zero
await admin.credits.setCredit(42, 0);
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| userId | number | Yes | -- | Target customer id (positional argument) |
| amount | number | Yes | -- | Adjustable credit amount to set (positional argument) |
Response
Returns boolean — true on success. On the wire the amount is sent under the backend's otherAmout field name.
Errors
| Code | Exception | When |
|---|---|---|
1001 | ValidationError | Invalid userId or amount |
2007 | PermissionError | Admin lacks Credit Management permission |
3001 | AuthenticationError | Session expired and refresh failed |