Skip to main content

Admin Credits — Python 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
get_credit()Read a customer's credit balance summary
set_credit()Adjust a customer's adjustable credit amount

get_credit​

Read a customer's credit/billing balance.

Example Usage​

balance = admin.credits.get_credit(user_id=42)
print(balance)

Parameters​

ParameterTypeRequiredDefaultDescription
user_idintYes--Target customer id (positional argument)

Response​

Returns a dict 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

set_credit​

Adjust a customer's adjustable credit amount.

Example Usage​

ok = admin.credits.set_credit(user_id=42, amount=100)
print(ok) # True

# Reset back to zero
admin.credits.set_credit(user_id=42, amount=0)

Parameters​

ParameterTypeRequiredDefaultDescription
user_idintYes--Target customer id (positional argument)
amountnumberYes--Adjustable credit amount to set (positional argument)

Response​

Returns bool — True on success. On the wire the amount is sent under the backend's otherAmout field name.

Errors​

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