Skip to main content

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​

MethodDescription
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​

ParameterTypeRequiredDefaultDescription
userIdnumberYes--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​

CodeExceptionWhen
2007PermissionErrorAdmin lacks Credit Management permission
3001AuthenticationErrorSession 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​

ParameterTypeRequiredDefaultDescription
userIdnumberYes--Target customer id (positional argument)
amountnumberYes--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​

CodeExceptionWhen
1001ValidationErrorInvalid userId or amount
2007PermissionErrorAdmin lacks Credit Management permission
3001AuthenticationErrorSession expired and refresh failed