MarzbanSDK
Modules

Admins

Create, update, query, and delete Marzban administrators — manage sudo privileges, Telegram and Discord links, and per-admin usage via `sdk.admin`.

sdk.admin provides endpoints for creating, updating, and querying Marzban administrators.

Types

Admin

Returned by getCurrentAdmin, createAdmin, modifyAdmin, and getAdmins.

import type { Admin } from 'marzban-sdk'
FieldTypeDescription
usernamestringAdmin username
is_sudobooleanSuperadmin flag — grants full access to all admins and users
telegram_idnumber | nullLinked Telegram account ID
discord_webhookstring | nullDiscord webhook URL for notifications
users_usagenumber | nullTotal traffic used by this admin's users (bytes)

AdminCreate

Payload for createAdmin.

import type { AdminCreate } from 'marzban-sdk'
FieldTypeRequiredDescription
usernamestringYesAdmin username
passwordstringYesInitial password
is_sudobooleanYesGrant superadmin privileges
telegram_idnumber | nullNoLinked Telegram account
discord_webhookstring | nullNoDiscord notification webhook

AdminModify

Payload for modifyAdmin. Note that username cannot be changed and is_sudo must always be sent (it is not optional, unlike the other fields).

import type { AdminModify } from 'marzban-sdk'
FieldTypeRequiredDescription
is_sudobooleanYesSuperadmin flag — must be provided on every update
passwordstring | nullNoNew password; omit or null to keep the current one
telegram_idnumber | nullNoLinked Telegram account
discord_webhookstring | nullNoDiscord notification webhook

Methods

getCurrentAdmin()

Get the profile of the currently authenticated admin.

Returns

const me = await sdk.admin.getCurrentAdmin()
console.log(me.username)
console.log(me.is_sudo)       // true for superadmin
console.log(me.telegram_id)

getAdmins(params?)

List all admins. Requires superadmin privileges.

Returns []

const admins = await sdk.admin.getAdmins({
  offset: 0,
  limit: 25,
  username: 'op',
})

for (const admin of admins) {
  console.log(admin.username, admin.is_sudo)
}

createAdmin(data)

Create a new admin account from an payload. Requires superadmin.

Returns

const admin = await sdk.admin.createAdmin({
  username: 'operator',
  password: 'strong-password',
  is_sudo: false,
  telegram_id: 123456789,
  discord_webhook: 'https://discord.com/api/webhooks/...',
})

console.log(admin.username)

modifyAdmin(username, data)

Update an admin's profile or permissions from an payload.

Returns

await sdk.admin.modifyAdmin('operator', {
  password: 'new-password',
  is_sudo: true,
})

removeAdmin(username)

Delete an admin account. Requires superadmin.

Returns

await sdk.admin.removeAdmin('operator')

getAdminUsage(username, params?)

Get traffic usage attributed to a specific admin's users.

Returns number — total bytes used

const usage = await sdk.admin.getAdminUsage('operator', {
  start: '2024-01-01T00:00:00',
  end:   '2024-01-31T23:59:59',
})

resetAdminUsage(username)

Reset the traffic usage counter for an admin.

Returns

await sdk.admin.resetAdminUsage('operator')

disableAllActiveUsers(username)

Disable all active users owned by a specific admin.

Returns

await sdk.admin.disableAllActiveUsers('operator')

activateAllDisabledUsers(username)

Re-activate all disabled users owned by a specific admin.

Returns

await sdk.admin.activateAllDisabledUsers('operator')

Common patterns

Bootstrap a new operator admin

const admin = await sdk.admin.createAdmin({
  username: 'ops-team',
  password: process.env.OPS_PASSWORD!,
  is_sudo: false,
})

console.log('Admin created:', admin.username)

Temporarily suspend all users of an admin

// Suspend
await sdk.admin.disableAllActiveUsers('operator')

// Later, restore
await sdk.admin.activateAllDisabledUsers('operator')

On this page