API Add User

From Virtualizor Wiki
Jump to: navigation, search
NOTE
This is OLD API Documentation. Click on the following link for New API Documentation
Admin API

Add a User

Parameters Type Description
adduser POST Flag to add a user (This has to be 1)
priority POST The user type (0 = End User / 1 = Admin / 2 = Cloud User)
newemail POST The email address of the user
newpass POST The password of the user
dnsplan_id POST The id of DNS Plan for the user (0 for no plan)
acl_id POST The id of ACL for the user (0 for no plan)
bandwidth POST Max Bandwidth in GB. Zero (0) for unlimited.
burst POST Max Burst / Swap in MB
cores POST Max Cores per VM.
cpu POST Default CPU Weight
cpu_percent POST Default CPU %
network_speed POST Network Speed
num_cores POST The id of DNS Plan for the user (0 for no plan)
num_ipv4 POST The id of DNS Plan for the user (0 for no plan)
num_ipv6 POST The id of DNS Plan for the user (0 for no plan)
num_ipv6_subnet POST The id of DNS Plan for the user (0 for no plan)
num_users POST The maximum number of sub-users this user can create. Zero (0) for unlimited.
num_vs POST The maximum number of Virtual Machines this user can create. Zero (0) for unlimited.
ram POST Max Ram in MB
space POST Max Disk Space in GB
upload_speed POST Upload Speed

Example Code

<?php

    require_once('admin.php');

    $key =  'uketenhrhpunty5lhgwkcuxxxxxxxxxx';

    $pass = 'yrsofc3tg3tre7bjpfppspxxxxxxxxxx';

    $ip = 'xxx.xxx.xxx.xxx';

    $admin = new Virtualizor_Admin_API($ip, $key, $pass);

    $post = array();
    $post['adduser'] = 1;
    $post['priority'] = 2;
    $post['newemail'] = 'adminapi@api.com';
    $post['newpass'] = 'password';
    $post['dnsplan_id'] = 0;
    
    //Only for Admin
    $post['acl_id'] = 1;
    //Only for Admin

    //Only for Cloud
    $post['bandwidth'] = 10;
    $post['burst'] = 1024;
    $post['cores'] = 4;
    $post['cpu'] = 10;
    $post['cpu_percent'] = 10;
    $post['network_speed'] = 128;
    $post['num_cores'] = 0;
    $post['num_ipv4'] = 10;
    $post['num_ipv6'] = 10;
    $post['num_ipv6_subnet'] = 10;
    $post['num_users'] = 10;
    $post['num_vs'] = 10;
    $post['ram'] = 2048;
    $post['space'] = 100;
    $post['upload_speed'] = 128;
    //Only for Cloud

    $output = $admin->adduser($post);
    print_r($output);
?>

Returns:

Array
(
    [title] => Add User
    [done] => 1
    [mgs] => Array
        (
            [1] => Array
                (
                    [mgid] => 1
                    [mg_name] => test
                    [mg_desc] => test
                    [mg_type] => kvm
                )

        )

    [servergroups] => Array
        (
            [0] => Array
                (
                    [sgid] => 0
                    [sg_name] => Default
                    [sg_desc] => Default Group
                    [sg_select] => 0
                )

            [2] => Array
                (
                    [sgid] => 2
                    [sg_name] => Group 1 [ US East ]
                    [sg_desc] => Group 1 [ US East ] description
                    [sg_select] => 0
                )

        )

    [timenow] => 1402989046
    [time_taken] => 0.020
)