User

Balance, profile, payments and the webhook URL — client.user.

balance

Balance in USD.

balance(): Promise<{ balance: number; zbalance: number; income?: number }>

balance includes the sum frozen by numbers in progress (zbalance): available = balance − zbalance. income is the partner income. The server caches the answer for 60 s.

const { balance, zbalance } = await client.user.balance()
const available = balance - zbalance

Errors: ApiError ERROR_WRONG_KEY, ACCOUNT_BLOCKED, API_ACCESS_DISABLED, API_ACCESS_IP.

profile

The account profile.

profile(): Promise<Profile>

Profile: { id, name, username, email, locale, currency, number_country, number_reject, webhook_url, api_access, … }.

const { email, webhook_url } = await client.user.profile()

paymentHistory

Top-up orders (paginated, newest first) and the available payment methods.

paymentHistory(page = 1): Promise<PaymentHistory>

PaymentHistory: { orders: Paginator<PaymentOrder>, paylist, domains?, forms?, currency?, buttons? }. PaymentOrder.sum stays a decimal string ("89.00").

const { orders } = await client.user.paymentHistory()
console.log(`${orders.total} orders, page ${orders.current_page}/${orders.last_page}`)

setWebhookUrl

Set the URL that receives SMS webhooks (see Webhooks).

setWebhookUrl(url: string): Promise<true>
await client.user.setWebhookUrl('https://example.com/onlinesim-hook')

Errors: ApiError VALIDATION_ERROR for an invalid URL; message holds the server's field messages.

clearWebhookUrl

Remove the webhook URL, also from operations in progress.

clearWebhookUrl(): Promise<true>
await client.user.clearWebhookUrl()

webhookLogs

Webhook delivery log, newest first, 10 per page.

webhookLogs(page = 1): Promise<Paginator<WebhookLog>>

WebhookLog: { id, user_id, webhook_url, type, params, status, error, created_at, updated_at } — type is receiving_sms or rent_sms, status is success, fail or pending, params the payload that was sent.

const logs = await client.user.webhookLogs()
for (const log of logs.data) console.log(log.created_at, log.status, log.error)