-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
To get started with DirectApi, first install it with composer
composer require avametix/directapi
Then open the PHP file you want to use it in and start with
<?php
// Other use declarations
use Avametix\DirectApi;
// ...
Proceed by configuring an instance
// ...
$instance = new DirectApi('da.domain.io', 'username', 'password');
// ...
Now you're all set to use any API command you can think of!
Since DirectApi is simply a wrapper for the DirectAdmin API, it does not offer a ton of funcions you should know about. All meaningful functions will be described below.
A list of DirectAdmin API commands can be found on the DirectAdmin Wiki.
The get function is used to send a GET request to the DirectAdmin API. Within it, you specify which command you want DirectAdmin to execute minus the CMD_API_ prefix and (optionally) the data to send with it.
// ...
// Returns all domains the currently authenticated user has access to
$result = $instance->get("SHOW_DOMAINS");
// ...
The post function is used to send a POST request to the DirectAdmin API, using the same variables as in the get() method described above. However this time the data is required.
// ...
// Set data to contain necessary data to create a user with package
$data = array(
'action' => "create",
'add' => "Submit",
'email' => "[email protected]",
'passwd' => "password123",
'passwd2' => "password123",
'domain' => "domain.com",
'package' => "Basic",
'ip' => "127.0.0.1",
'notify' => "yes"
);
// Execute command as reseller
$instance->post("ACCOUNT_USER", $data);
// ...
Adds a username to authenticate DirectAdmin requests width, functions as the 'login as' button in the web panel. This way an admin can execute commands as if they were logged in as the specified user.
// ...
$instance->login_as("john");
// ...
Removes the second username after using the login_as() function.
// ...
$instance->logout();
// ...