Use the change hostname API to change the hostname of the server. The API response will contain "done" as "1" after the hostname is updated.
The changes will be reflected only after the server reboots.
HTTP Request
https://hostname:4085/index.php?act=hostname
Parameters
Name | Method | Value | Description | Required |
---|---|---|---|---|
act | GET | hostname | The action specified to perform operation and retrieve data | Yes |
changehost | POST | 1/0 | This should be set as 1 for updating the hostname | Yes |
newhost | POST | text | Set the new hostname | Yes |
Sample Code
<?php
require_once('/usr/local/virtualizor/sdk/admin.php');
$key = 'your_api_key';
$pass = 'your_api_pass';
$ip = 'your_server_ip';
$admin = new Virtualizor_Admin_API($ip, $key, $pass);
$post = array();
$post['changehost'] = 1;
$post['newhost'] = 'test.hostname';
$output = $admin->hostname($post);
print_r(json_encode($output));
?>
Output
{
"title": "Hostname",
"done": 1,
"timenow": 1536247931,
"time_taken": "0.246"
}