PHP code example of bl4ckp4nd4 / sanaei-api

1. Go to this page and download the library: Download bl4ckp4nd4/sanaei-api 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/ */

    

bl4ckp4nd4 / sanaei-api example snippets


use Bl4ckp4nd4\SanaeiApi\Sanaei;

$api = new Sanaei(
    url: 'example.com',
    username: 'your_username',
    password: 'your_password',
    webPath: 'panel', // Optional
    port: 443,        // Optional
    protocol: 'https' // Optional
);

$response = $api->login();
if ($response['success']) {
    echo "Login successful!";
} else {
    echo "Login failed: " . $response['msg'];
}

$inbounds = $api->inbounds();
if ($inbounds['success']) {
    print_r($inbounds['data']);
} else {
    echo "Failed to retrieve inbounds: " . $inbounds['msg'];
}

$response = $api->addClient(
    id: 'inbound_id',
    uuid: 'client_uuid',
    email: '[email protected]',
    totalgb: 100,
    eT: time() + (30 * 24 * 60 * 60), // Expire in 30 days
    limitIp: 1,
    subId: 'unique_subscription_id'
);

if ($response['success']) {
    echo "Client added successfully!";
} else {
    echo "Failed to add client: " . $response['msg'];
}

$response = $api->updateInbound(
    inboundId: 1,
    up: 1000000,
    down: 1000000,
    total: 2000000,
    remark: 'Updated Inbound',
    enable: true,
    expiryTime: time() + (7 * 24 * 60 * 60), // Expire in 7 days
    listen: '',
    port: 8080,
    protocol: 'vless',
    settings: [],
    streamSettings: [],
    sniffing: [],
    allocate: []
);

if ($response['success']) {
    echo "Inbound updated successfully!";
} else {
    echo "Failed to update inbound: " . $response['msg'];
}

$response = $api->clearClientIps('[email protected]');
if ($response['success']) {
    echo "Client IPs cleared successfully!";
} else {
    echo "Failed to clear client IPs: " . $response['msg'];
}