1. Go to this page and download the library: Download mkhab7/v2board-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mkhab7 / v2board-sdk example snippets
khab7\V2Board\SDK\V2BoardSDK;
// Initialize SDK with API version
$sdk = new V2BoardSDK('https://your-v2board-instance.com', [
'api_version' => 'v1' // Change to 'v2', 'v3', etc. as needed
]);
// Login
try {
$response = $sdk->login('[email protected]', 'your-password');
echo "Login successful! Token: " . $sdk->getToken();
echo "API Version: " . $sdk->getApiVersion();
} catch (Exception $e) {
echo "Login failed: " . $e->getMessage();
}
// Login with credentials
$response = $sdk->login($email, $password);
// Check if user is logged in
if ($sdk->isAuthenticated()) {
echo "User is logged in";
}
// Get current token
$token = $sdk->getToken();
// Check if user is admin
if ($sdk->isAdmin()) {
echo "User has admin privileges";
}
// Get JWT auth data
$authData = $sdk->getAuthData();
// Change API version
$sdk->setApiVersion('v2');
// Get current API version
$version = $sdk->getApiVersion();
// Logout
$sdk->logout();
// Enable caching (optional)
$sdk->auth()->setCacheEnabled(true);
// Set cache TTL in seconds (default: 3600 = 1 hour)
$sdk->auth()->setCacheTtl(1800); // 30 minutes
// Set custom cache file location
$sdk->auth()->setCacheFile('/path/to/custom/cache.json');
// With caching enabled, subsequent login() calls will use cached data
// if it hasn't expired, avoiding unnecessary API requests
// In your Laravel application
$sdk = new V2BoardSDK('https://your-v2board.com');
// Configure caching with Laravel's cache system
$sdk->auth()->setCacheEnabled(true);
$sdk->auth()->setCacheTtl(now()->addMinutes(30)->diffInSeconds());
$sdk->auth()->setCacheDriver(function($action, $key, $value = null, $ttl = null) {
return cache()->remember(
key: "v2board-auth.{$key}",
ttl: now()->addSeconds($ttl),
callback: fn() => $value
);
});
// Login (will be cached for 30 minutes)
$sdk->login('[email protected]', 'password');
// Get user email
$email = $sdk->user()->getEmail();
// Get transfer limit in GB
$transferGB = $sdk->user()->getTransferEnableGB();
// Get account balance
$balance = $sdk->user()->getBalance();
// Get current plan ID
$planId = $sdk->user()->getPlanId();
// Check if account is banned
if ($sdk->user()->isBanned()) {
echo "Account is suspended";
}
// Get user UUID
$uuid = $sdk->user()->getUuid();
// Get avatar URL
$avatarUrl = $sdk->user()->getAvatarUrl();
// Get system status
$status = $sdk->stats()->getStatus();
// Get number of running processes
$processes = $sdk->stats()->getProcesses();
// Get failed job count
$failedJobs = $sdk->stats()->getFailedJobs();
// Get recent job count
$recentJobs = $sdk->stats()->getRecentJobs();
// Get jobs per minute
$jobsPerMinute = $sdk->stats()->getJobsPerMinute();
// Set node ID for admin operations
$sdk->setNodeId('your-node-id');
// Get admin statistics
$onlineUsers = $sdk->admin()->getOnlineUsers();
$monthIncome = $sdk->admin()->getMonthIncome();
$monthRegisterTotal = $sdk->admin()->getMonthRegisterTotal();
// Search users by email
$user = $sdk->admin()->fetchUserByEmail('[email protected]');
// Search users by ID
$user = $sdk->admin()->fetchUserById(10);
// Search users by token
$user = $sdk->admin()->fetchUserByToken('user_token_here');
// Generate new user
$userData = [
'email_prefix' => 'newuser',
'email_suffix' => 'gmail.com',
'password' => '123456',
'expired_at' => '1752125627',
'plan_id' => '2'
];
$result = $sdk->generateUser($userData);
// Update existing user
$updateData = [
'id' => '1',
'email' => '[email protected]',
'balance' => '100',
'plan_id' => '3',
'transfer_enable' => '1073741824',
'banned' => '0'
];
$result = $sdk->updateUser($updateData);
// Get all plans
$plans = $sdk->plan()->fetch();
// Find plan by ID
$plan = $sdk->plan()->getPlanById(1);
// Find plan by name
$plan = $sdk->plan()->getPlanByName('25 GB');
// Get plans for specific group
$plans = $sdk->plan()->getPlansByGroupId(1);
// Get only visible plans
$visiblePlans = $sdk->plan()->getVisiblePlans();
// Get total plan count
$planCount = $sdk->plan()->getPlanCount();
// Get total users across all plans
$totalUsers = $sdk->plan()->getTotalUserCount();
// Create or update plan
$planData = [
'id' => '1',
'group_id' => '1',
'transfer_enable' => '.5',
'name' => '1 GB',
'show' => '1',
'sort' => '1',
'renew' => '1'
];
$result = $sdk->plan()->save($planData);
// Get all server groups
$groups = $sdk->serverGroup()->fetch();
// Find group by ID
$group = $sdk->serverGroup()->getGroupById(1);
// Find group by name
$group = $sdk->serverGroup()->getGroupByName('normal');
// Get total group count
$groupCount = $sdk->serverGroup()->getGroupCount();
// Get total users across all groups
$totalUsers = $sdk->serverGroup()->getTotalUserCount();
// Get total servers across all groups
$totalServers = $sdk->serverGroup()->getTotalServerCount();
// Make custom GET request
$response = $sdk->http()->get('/api/v1/custom/endpoint');
// Make custom POST request
$response = $sdk->http()->post('/api/v1/custom/endpoint', [
'key' => 'value'
]);