### Installation Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Install the Hostinger PHP SDK using Composer. ```APIDOC ## Installation You can install the package via composer: ```bash composer require derrickob/hostinger-php-sdk ``` ``` -------------------------------- ### List and Get VPS OS Templates Source: https://context7.com/derrickobedgiu1/hostinger-php-sdk/llms.txt Fetch available operating system templates for VPS installations. You can list all available templates or retrieve details for a specific one using its ID. ```php vps()->templates()->list(); foreach ($templates as $template) { echo "ID: " . $template->id . "\n"; echo "Name: " . $template->name . "\n"; echo "Description: " . $template->description . "\n"; echo "Docs: " . ($template->documentation ?? 'N/A') . "\n\n"; } // Get specific template details $template = $hostinger->vps()->templates()->get(2868928); ``` -------------------------------- ### Start Virtual Machine Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Starts a virtual machine that is currently in a stopped state. This action initiates the VM's operation. ```php $virtualMachineId = 1268054; $action = $hostinger->vps()->virtualMachines()->start($virtualMachineId); $action->id; // 8123729 $action->name; // start $action->state->value; // success $action->created_at->format('Y-m-d H:i:s'); // 2025-02-27 11:54:00 $action->updated_at->format('Y-m-d H:i:s'); // 2025-02-27 11:58:00 $action->toArray(); // ['id' => 8123729, 'name' => 'start', 'state' => 'success', ...] ``` -------------------------------- ### Start Virtual Machine Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Starts a virtual machine that is currently in a stopped state. ```APIDOC ## POST /api/vps/v1/virtual-machines/{virtualMachineId}/start ### Description Starts a stopped virtual machine. ### Method POST ### Endpoint /api/vps/v1/virtual-machines/{virtualMachineId}/start ### Parameters #### Path Parameters - **virtualMachineId** (integer) - Required - The ID of the virtual machine to start. ### Request Example ```php $virtualMachineId = 1268054; $action = $hostinger->vps()->virtualMachines()->start($virtualMachineId); ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the action. - **name** (string) - The name of the action performed. - **state** (object) - The state of the action. - **value** (string) - The value of the state (e.g., 'success'). - **created_at** (datetime) - The timestamp when the action was created. - **updated_at** (datetime) - The timestamp when the action was last updated. #### Response Example ```json { "id": 8123729, "name": "start", "state": {"value": "success"}, "created_at": "2025-02-27 11:54:00", "updated_at": "2025-02-27 11:58:00" } ``` ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/CONTRIBUTING.md Use these bash commands to clone the repository and install project dependencies using Composer. ```bash git clone https://github.com/derrickobedgiu1/hostinger-php-sdk.git cd hostinger-php-sdk composer install ``` -------------------------------- ### Virtual Machine API Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Manage virtual machines, including getting attached public keys, setting hostnames, resetting hostnames, getting VM details, purchasing new VMs, getting metrics, setting nameservers, setting panel passwords, recreating VMs, restarting VMs, setting root passwords, setting up new VMs, starting VMs, and stopping VMs. ```APIDOC ## Virtual Machine - [Get Attached Public Keys](#get-attached-public-keys) - [Set Hostname](#set-hostname) - [Reset Hostname](#reset-hostname) - [Get Virtual Machine](#get-virtual-machine) - [Get Virtual Machine List](#get-virtual-machine-list) - [Purchase New Virtual Machine](#purchase-new-virtual-machine) - [Get Metrics](#get-metrics) - [Set Nameservers](#set-nameservers) - [Set Panel Password](#set-panel-password) - [Recreate Virtual Machine](#recreate-virtual-machine) - [Restart Virtual Machine](#restart-virtual-machine) - [Set Root Password](#set-root-password) - [Setup New Virtual Machine](#setup-new-virtual-machine) - [Start Virtual Machine](#start-virtual-machine) - [Stop Virtual Machine](#stop-virtual-machine) ``` -------------------------------- ### Install Monarx Malware Scanner in PHP Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Installs the Monarx malware scanner on a specified VM. The action returns details about the installation process, including its state. ```php $virtualMachineId = 1268054; $action = $hostinger->vps()->malwareScanner()->install($virtualMachineId); $action->id; // 8123718 $action->name; // install_monarx $action->state->value; // success $action->created_at->format('Y-m-d H:i:s'); // 2025-02-27 11:54:00 $action->updated_at->format('Y-m-d H:i:s'); // 2025-02-27 11:58:00 $action->toArray(); // ['id' => 8123718, 'name' => 'install_monarx', 'state' => 'success', ...] ``` -------------------------------- ### Install Monarx Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Installs the Monarx malware scanner on a VM. ```APIDOC ## POST /api/vps/v1/virtual-machines/{virtualMachineId}/monarx ### Description Installs the Monarx malware scanner on a VM. ### Method POST ### Endpoint /api/vps/v1/virtual-machines/{virtualMachineId}/monarx ### Parameters #### Path Parameters - **virtualMachineId** (integer) - Required - The ID of the virtual machine. ### Request Example ```php $virtualMachineId = 1268054; $action = $hostinger->vps()->malwareScanner()->install($virtualMachineId); ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the installation action. - **name** (string) - The name of the action (e.g., 'install_monarx'). - **state** (object) - The state of the installation action (e.g., 'success'). - **created_at** (datetime) - The timestamp when the action was created. - **updated_at** (datetime) - The timestamp when the action was last updated. #### Response Example ```json { "id": 8123718, "name": "install_monarx", "state": {"value": "success"}, "created_at": "2025-02-27 11:54:00", "updated_at": "2025-02-27 11:58:00" } ``` ``` -------------------------------- ### Create Example Resource Class in PHP Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/CONTRIBUTING.md Extend the Resource class and implement methods for API operations like listing and getting resources. Use the transform method to convert API responses to Data Transfer Objects (DTOs). ```php getApiVersion(); $response = $this->client->get(sprintf('/api/example/%s/examples', $version), $query); return $this->transform(ExampleData::class, $response); } /** * Get a specific example * * @param int $id Example ID * @return ExampleData */ public function get(int $id): ExampleData { $version = $this->getApiVersion(); $response = $this->client->get(sprintf('/api/example/%s/examples/%d', $version, $id)); return $this->transform(ExampleData::class, $response); } } ``` -------------------------------- ### Post-Install Scripts API Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Manage post-install scripts to be executed after OS installation on virtual machines. ```APIDOC ## GET /api/vps/v1/post-install-scripts/{postInstallScriptId} ### Description Retrieves details of a specific post-install script. ### Method GET ### Endpoint /api/vps/v1/post-install-scripts/{postInstallScriptId} ### Parameters #### Path Parameters - **postInstallScriptId** (integer) - Required - The ID of the post-install script. ### Response #### Success Response (200) - **id** (integer) - The ID of the post-install script. - **name** (string) - The name of the post-install script. - **content** (string) - The content of the script. - **created_at** (datetime) - The timestamp when the script was created. - **updated_at** (datetime) - The timestamp when the script was last updated. ### Request Example ```php $postInstallScriptId = 9568314; $script = $hostinger->vps()->postInstallScripts()->get($postInstallScriptId); ``` ### Response Example ```json { "id": 325, "name": "My Setup Script", "content": "#!/bin/bash\napt-get update...", "created_at": "2025-02-27 11:54:22", "updated_at": "2025-03-19 11:54:22" } ``` ## PUT /api/vps/v1/post-install-scripts/{postInstallScriptId} ### Description Updates the name and/or content of an existing post-install script. ### Method PUT ### Endpoint /api/vps/v1/post-install-scripts/{postInstallScriptId} ### Parameters #### Path Parameters - **postInstallScriptId** (integer) - Required - The ID of the post-install script to update. #### Request Body - **name** (string) - Optional - The new name for the post-install script. - **content** (string) - Optional - The new content for the post-install script. ### Request Example ```php $postInstallScriptId = 9568314; $data = [ 'name' => 'Updated Setup Script', 'content' => "#!/bin/bash\napt-get update && apt-get upgrade -y", ]; $script = $hostinger->vps()->postInstallScripts()->update($postInstallScriptId, $data); ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the updated post-install script. - **name** (string) - The updated name of the post-install script. - **content** (string) - The updated content of the script. - **created_at** (datetime) - The timestamp when the script was created. - **updated_at** (datetime) - The timestamp when the script was last updated. ### Response Example ```json { "id": 9568314, "name": "Updated Setup Script", "content": "#!/bin/bash\napt-get update && apt-get upgrade -y", "created_at": "2025-02-27 11:54:22", "updated_at": "2025-04-01 10:30:00" } ``` ## DELETE /api/vps/v1/post-install-scripts/{postInstallScriptId} ### Description Deletes a post-install script from your account. ### Method DELETE ### Endpoint /api/vps/v1/post-install-scripts/{postInstallScriptId} ### Parameters #### Path Parameters - **postInstallScriptId** (integer) - Required - The ID of the post-install script to delete. ### Response #### Success Response (200) - **message** (string) - A confirmation message (e.g., "Request accepted"). ### Request Example ```php $postInstallScriptId = 9568314; $response = $hostinger->vps()->postInstallScripts()->delete($postInstallScriptId); ``` ### Response Example ```json { "message": "Request accepted" } ``` ``` -------------------------------- ### List Available OS Templates Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Fetches a list of all available OS templates that can be used for installing on virtual machines. Each template in the list can be iterated over to access its properties. ```php $templates = $hostinger->vps()->templates()->list(); foreach ($templates as $template) { $template->id; // 6523 $template->name; // Ubuntu 20.04 LTS $template->description; // Ubuntu 20.04 LTS $template->documentation; // https://docs.ubuntu.com or null $template->toArray(); // ['id' => 6523, 'name' => 'Ubuntu 20.04 LTS', 'description' => '...', 'documentation' => '...'] } ``` -------------------------------- ### Install Hostinger PHP SDK via Composer Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Use this command to add the Hostinger PHP SDK to your project dependencies. ```bash composer require derrickob/hostinger-php-sdk ``` -------------------------------- ### Run Test Suite Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Executes the project's test suite using Composer and Pest. Ensure dependencies are installed via Composer. ```bash composer test ``` -------------------------------- ### Get Post-Install Script Details Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Retrieves the details of a specific post-install script using its ID. The script object includes its name, content, and creation/update timestamps. ```php $postInstallScriptId = 9568314; $script = $hostinger->vps()->postInstallScripts()->get($postInstallScriptId); $script->id; // 325 $script->name; // My Setup Script $script->content; // #!/bin/bash\napt-get update... $script->created_at->format('Y-m-d H:i:s'); // 2025-02-27 11:54:22 $script->updated_at->format('Y-m-d H:i:s'); // 2025-03-19 11:54:22 $script->toArray(); // ['id' => 325, 'name' => '...', 'content' => '...', 'created_at' => ..., 'updated_at' => ...] ``` -------------------------------- ### Setup New Virtual Machine Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Configures a newly purchased VPS that is in the 'initial' state. Requires specifying an OS template and data center. Optional parameters include setting a password, hostname, enabling backups, and adding SSH keys. ```php $virtualMachineId = 1268054; $data = [ 'template_id' => 1130, 'data_center_id' => 19, 'password' => 'MyS3cureP@ssw0rd!', // Optional: Strong password, random if omitted 'hostname' => 'my.server.tld', // Optional: Override default hostname 'install_monarx' => false, // Optional: Install malware scanner (default: false) 'enable_backups' => true, // Optional: Enable weekly backups (default: true) 'ns1' => '1.1.1.1', // Optional: Primary DNS resolver 'ns2' => '1.0.0.1', // Optional: Secondary DNS resolver 'post_install_script_id' => 6324, // Optional: Script to run after setup 'public_key' => [ // Optional: Add and attach a new SSH key 'name' => 'my-setup-key', 'key' => 'ssh-rsa AAAAB3NzaC1yc2EAAA...', ] ]; $vm = $hostinger->vps()->virtualMachines()->setup($virtualMachineId, $data); $vm->id; // 1268054 $vm->firewall_group_id; // null $vm->subscription_id; // Azz353Uhl1xC54pR0 $vm->plan; // KVM 4 $vm->hostname; // my.server.tld $vm->state->value; // creating $vm->actions_lock->value; // unlocked $vm->cpus; // 4 $vm->memory; // 8192 $vm->disk; // 51200 $vm->bandwidth; // 1073741824 $vm->ns1; // 1.1.1.1 $vm->ns2; // 1.0.0.1 $vm->created_at->format('Y-m-d H:i:s'); // 2024-09-05 07:25:36 if ($vm->ipv4) { foreach ($vm->ipv4 as $ipv4) { $ipv4->id; // 52347 $ipv4->address; // 213.331.273.15 $ipv4->ptr; // something.domain.tld $ipv4->toArray(); // ['id' => 52347, 'address' => '...', 'ptr' => '...'] } } if ($vm->ipv6) { foreach ($vm->ipv6 as $ipv6) { $ipv6->id; // 52347 $ipv6->address; // 2a00:4000:f:eaee::1 $ipv6->ptr; // something.domain.tld $ipv6->toArray(); // ['id' => 52347, 'address' => '...', 'ptr' => '...'] } } if ($vm->template) { $vm->template->id; // 6523 $vm->template->name; // Ubuntu 20.04 LTS $vm->template->description; // Ubuntu 20.04 LTS $vm->template->documentation; // https://docs.ubuntu.com $vm->template->toArray(); // ['id' => 6523, 'name' => '...', ...] } $vm->toArray(); // ['id' => 1268054, 'firewall_group_id' => null, 'hostname' => 'my.server.tld', 'state' => 'creating', ...] ``` -------------------------------- ### Setup New Virtual Machine Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Initializes a newly purchased virtual machine (in 'initial' state). This process requires specifying an OS template and a data center. ```APIDOC ## POST /api/vps/v1/virtual-machines/{virtualMachineId}/setup ### Description Sets up a newly purchased VPS (in `initial` state). Requires OS template and data center. ### Method POST ### Endpoint /api/vps/v1/virtual-machines/{virtualMachineId}/setup ### Parameters #### Path Parameters - **virtualMachineId** (integer) - Required - The ID of the virtual machine to set up. #### Request Body - **template_id** (integer) - Required - The ID of the OS template to install. - **data_center_id** (integer) - Required - The ID of the data center where the VM will be located. - **password** (string) - Optional - A strong password for the root user. If omitted, a random password will be generated. - **hostname** (string) - Optional - Overrides the default hostname for the VM. - **install_monarx** (boolean) - Optional - Whether to install the Monarx malware scanner. Defaults to false. - **enable_backups** (boolean) - Optional - Whether to enable weekly backups. Defaults to true. - **ns1** (string) - Optional - The primary DNS resolver IP address. - **ns2** (string) - Optional - The secondary DNS resolver IP address. - **post_install_script_id** (integer) - Optional - The ID of a script to run after the VM setup is complete. - **public_key** (object) - Optional - An object containing details for a new SSH key to be added. - **name** (string) - Required - The name for the SSH key. - **key** (string) - Required - The public SSH key content. ### Request Example ```php $virtualMachineId = 1268054; $data = [ 'template_id' => 1130, 'data_center_id' => 19, 'password' => 'MyS3cureP@ssw0rd!', // Optional: Strong password, random if omitted 'hostname' => 'my.server.tld', // Optional: Override default hostname 'install_monarx' => false, // Optional: Install malware scanner (default: false) 'enable_backups' => true, // Optional: Enable weekly backups (default: true) 'ns1' => '1.1.1.1', // Optional: Primary DNS resolver 'ns2' => '1.0.0.1', // Optional: Secondary DNS resolver 'post_install_script_id' => 6324, // Optional: Script to run after setup 'public_key' => [ 'name' => 'my-setup-key', 'key' => 'ssh-rsa AAAAB3NzaC1yc2EAAA...' ] ]; $vm = $hostinger->vps()->virtualMachines()->setup($virtualMachineId, $data); ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the virtual machine. - **firewall_group_id** (integer|null) - The ID of the associated firewall group, if any. - **subscription_id** (string) - The ID of the subscription associated with the VM. - **plan** (string) - The name of the VM plan. - **hostname** (string) - The hostname of the VM. - **state** (object) - The current state of the VM. - **value** (string) - The value of the state (e.g., 'creating'). - **actions_lock** (object) - Indicates if actions on the VM are locked. - **value** (string) - The value of the lock state (e.g., 'unlocked'). - **cpus** (integer) - The number of CPU cores allocated to the VM. - **memory** (integer) - The amount of memory (in MB) allocated to the VM. - **disk** (integer) - The amount of disk space (in MB) allocated to the VM. - **bandwidth** (integer) - The bandwidth limit (in bytes) for the VM. - **ns1** (string) - The primary DNS resolver IP address. - **ns2** (string) - The secondary DNS resolver IP address. - **created_at** (datetime) - The timestamp when the VM was created. - **ipv4** (array) - An array of IPv4 addresses assigned to the VM. - **id** (integer) - The ID of the IPv4 address. - **address** (string) - The IPv4 address. - **ptr** (string) - The PTR record for the IPv4 address. - **ipv6** (array) - An array of IPv6 addresses assigned to the VM. - **id** (integer) - The ID of the IPv6 address. - **address** (string) - The IPv6 address. - **ptr** (string) - The PTR record for the IPv6 address. - **template** (object) - Information about the OS template used. - **id** (integer) - The ID of the template. - **name** (string) - The name of the template. - **description** (string) - A description of the template. - **documentation** (string) - A URL to the template's documentation. #### Response Example ```json { "id": 1268054, "firewall_group_id": null, "subscription_id": "Azz353Uhl1xC54pR0", "plan": "KVM 4", "hostname": "my.server.tld", "state": {"value": "creating"}, "actions_lock": {"value": "unlocked"}, "cpus": 4, "memory": 8192, "disk": 51200, "bandwidth": 1073741824, "ns1": "1.1.1.1", "ns2": "1.0.0.1", "created_at": "2024-09-05 07:25:36", "ipv4": [ { "id": 52347, "address": "213.331.273.15", "ptr": "something.domain.tld" } ], "ipv6": [ { "id": 52347, "address": "2a00:4000:f:eaee::1", "ptr": "something.domain.tld" } ], "template": { "id": 6523, "name": "Ubuntu 20.04 LTS", "description": "Ubuntu 20.04 LTS", "documentation": "https://docs.ubuntu.com" } } ``` ``` -------------------------------- ### Initialize the Client Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Demonstrates how to initialize the Hostinger client with an API token, with options for timeout, base URL, and API version. ```APIDOC ### Initialize the Client ```php use DerrickOb\HostingerApi\Hostinger; // Initialize with just an API token $hostinger = new Hostinger('your-api-token'); // Or with additional options $hostinger = new Hostinger('your-api-token', [ 'timeout' => 30, // Request timeout in seconds 'base_url' => 'https://developers.hostinger.com', // API base URL 'api_version' => 'v1', // API version ]); ``` ``` -------------------------------- ### Purchase and Setup a New VPS Source: https://context7.com/derrickobedgiu1/hostinger-php-sdk/llms.txt Use this to purchase and configure a new VPS instance. Ensure you have valid `item_id`, `payment_method_id`, and `template_id`. Strong passwords and SSH keys are recommended. ```php vps()->virtualMachines()->purchase([ 'item_id' => 'hostingercom-vps-kvm2-usd-1m', 'payment_method_id' => 1327362, 'setup' => [ 'template_id' => 1130, // Ubuntu 22.04 'data_center_id' => 19, // Data center location 'hostname' => 'myserver.example.com', 'password' => 'MyS3cur3P@ss!', 'install_monarx' => true, // Malware scanner 'enable_backups' => true, 'ns1' => '1.1.1.1', 'ns2' => '8.8.8.8', 'public_key' => [ 'name' => 'my-ssh-key', 'key' => 'ssh-rsa AAAAB3NzaC1yc2EAAA...', ], ], 'coupons' => ['VPSPROMO'], ]); echo "Order ID: " . $result->order->id . "\n"; echo "VM ID: " . $result->virtual_machine->id . "\n"; ``` -------------------------------- ### Create Post-Install Script Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Creates a new post-install script for a VM. The maximum script size is 48KB. The script content should be a valid shell script. ```php $data = [ 'name' => 'Install Docker Script', 'content' => "#!/bin/bash\napt-get update\napt-get install -y docker.io", ]; $script = $hostinger->vps()->postInstallScripts()->create($data); $script->id; // 326 $script->name; // Install Docker Script $script->content; // "#!/bin/bash\napt-get update\napt-get install -y docker.io" $script->created_at->format('Y-m-d H:i:s'); // 2025-04-01 10:00:00 $script->updated_at->format('Y-m-d H:i:s'); // 2025-04-01 10:00:00 $script->toArray(); // ['id' => 326, 'name' => 'Install Docker Script', 'content' => '...', ...] ``` -------------------------------- ### Purchase New Virtual Machine Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Allows you to buy (purchase) and set up a new virtual machine. If setup fails, manual completion in hPanel is required. Uses default payment method if none is specified. ```APIDOC ## POST /api/vps/v1/virtual-machines ### Description Allows you to buy (purchase) and setup a new virtual machine. If virtual machine setup fails for any reason, login to hPanel and complete the setup manually. If no payment method is provided, your default payment method will be used automatically. ### Method POST ### Endpoint /api/vps/v1/virtual-machines ### Parameters #### Request Body - **item_id** (string) - Required - The ID of the virtual machine product to purchase (e.g., 'hostingercom-vps-kvm2-usd-1m'). - **payment_method_id** (integer) - Optional - The ID of the payment method to use. If not provided, the default payment method will be used. - **setup** (object) - Required - Configuration details for setting up the virtual machine. - **template_id** (integer) - Required - The ID of the OS template to install. - **data_center_id** (integer) - Required - The ID of the data center where the VM will be hosted. - **post_install_script_id** (integer) - Optional - The ID of a post-installation script to run. - **password** (string) - Required - The password for the virtual machine. - **hostname** (string) - Required - The desired hostname for the virtual machine. - **install_monarx** (boolean) - Optional - Whether to install Monarx security agent (defaults to false). - **enable_backups** (boolean) - Optional - Whether to enable backups for the VM (defaults to true). - **ns1** (string) - Optional - The primary nameserver address. - **ns2** (string) - Optional - The secondary nameserver address. - **public_key** (object) - Optional - SSH public key details. - **name** (string) - Required - The name of the SSH key. - **key** (string) - Required - The SSH public key string. - **coupons** (array) - Optional - An array of coupon codes to apply to the purchase. ### Request Example ```json { "item_id": "hostingercom-vps-kvm2-usd-1m", "payment_method_id": 1327362, "setup": { "template_id": 1130, "data_center_id": 19, "post_install_script_id": 6324, "password": "MyS3cureP@ssw0rd!", "hostname": "my.server.tld", "install_monarx": false, "enable_backups": true, "ns1": "1.1.1.1", "ns2": "1.0.0.1", "public_key": { "name": "my-key", "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC2X..." } }, "coupons": ["VPSPROMO"] } ``` ### Response #### Success Response (200) - **order** (object) - Details about the purchase order. - **id** (integer) - The order ID. - **subscription_id** (string) - The subscription ID associated with the order. - **status** (object) - The status of the order (e.g., 'completed'). - **currency** (string) - The currency used for the order. - **subtotal** (float) - The subtotal amount of the order. - **total** (float) - The total amount of the order. - **billing_address** (object) - The billing address details. - **created_at** (datetime) - The timestamp when the order was created. - **updated_at** (datetime) - The timestamp when the order was last updated. - **virtual_machine** (object) - Details about the newly purchased virtual machine. - **id** (integer) - The VM ID. - **hostname** (string) - The hostname of the VM. - **state** (object) - The current state of the VM (e.g., 'creating'). - **plan** (string) - The plan of the VM. - **cpus** (integer) - Number of CPUs. - **memory** (integer) - Memory in MB. - **disk** (integer) - Disk space in MB. #### Response Example ```json { "order": { "id": 2957087, "subscription_id": "Azz353Uhl1xC54pR0", "status": {"value": "completed"}, "currency": "USD", "subtotal": 899, "total": 1080, "billing_address": { "first_name": "John", "last_name": "Doe", "company": null, "address_1": null, "address_2": null, "city": null, "state": null, "zip": null, "country": "NL", "phone": null, "email": "john@doe.tld" }, "created_at": "2025-02-27 11:54:22", "updated_at": "2025-02-27 11:54:22" }, "virtual_machine": { "id": 1268054, "hostname": "my.server.tld", "state": {"value": "creating"}, "plan": "KVM 4", "cpus": 4, "memory": 8192, "disk": 51200 } } ``` ``` -------------------------------- ### GET /api/dns/v1/zones/{domain} - Get Records Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Retrieves all DNS records for a specific domain. ```APIDOC ## GET /api/dns/v1/zones/{domain} ### Description Retrieves all DNS records for a specific domain. ### Method GET ### Endpoint /api/dns/v1/zones/{domain} ### Parameters #### Path Parameters - **domain** (string) - Required - The domain name for which to retrieve DNS records. ### Response #### Success Response (200) - **name** (string) - The name of the DNS record group (e.g., 'www'). - **type** (string) - The type of the DNS record (e.g., 'A'). - **ttl** (integer) - The Time To Live for the record. - **records** (array) - An array of record values. - **content** (string) - The content of the DNS record. - **is_disabled** (boolean) - Indicates if the record is disabled. ### Response Example ```json [ { "name": "www", "type": "A", "ttl": 14400, "records": [ { "content": "mydomain.tld.", "is_disabled": false } ] } ] ``` ``` -------------------------------- ### Restart Virtual Machine Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Restarts a virtual machine. This action is equivalent to stopping and then starting the VM. It can also be used to start a VM that is currently stopped. ```APIDOC ## POST /api/vps/v1/virtual-machines/{virtualMachineId}/restart ### Description Restarts a virtual machine (equivalent to stop then start). Starts a stopped VM. ### Method POST ### Endpoint /api/vps/v1/virtual-machines/{virtualMachineId}/restart ### Parameters #### Path Parameters - **virtualMachineId** (integer) - Required - The ID of the virtual machine to restart. ### Request Example ```php $virtualMachineId = 1268054; $action = $hostinger->vps()->virtualMachines()->restart($virtualMachineId); ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the action. - **name** (string) - The name of the action performed. - **state** (object) - The state of the action. - **value** (string) - The value of the state (e.g., 'success'). - **created_at** (datetime) - The timestamp when the action was created. - **updated_at** (datetime) - The timestamp when the action was last updated. #### Response Example ```json { "id": 8123712, "name": "restart", "state": {"value": "success"}, "created_at": "2025-02-27 11:54:00", "updated_at": "2025-02-27 11:58:00" } ``` ``` -------------------------------- ### Initialize Hostinger Client Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Instantiate the Hostinger client using your API token. Optional parameters like timeout, base URL, and API version can be provided. ```php use DerrickOb\HostingerApi\Hostinger; // Initialize with just an API token $hostinger = new Hostinger('your-api-token'); // Or with additional options $hostinger = new Hostinger('your-api-token', [ 'timeout' => 30, // Request timeout in seconds 'base_url' => 'https://developers.hostinger.com', // API base URL 'api_version' => 'v1', // API version ]); ``` -------------------------------- ### POST /api/vps/v1/virtual-machines/{virtualMachineId}/recreate Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Reinstalls the OS on a virtual machine. Warning: All data will be lost! Snapshots will be deleted. Requires a strong password if provided. ```APIDOC ## POST /api/vps/v1/virtual-machines/{virtualMachineId}/recreate ### Description Reinstalls the OS on a virtual machine. **Warning: All data will be lost! Snapshots will be deleted.** Requires a strong password if provided. ### Method POST ### Endpoint /api/vps/v1/virtual-machines/{virtualMachineId}/recreate ### Parameters #### Path Parameters - **virtualMachineId** (integer) - Required - The ID of the virtual machine. #### Request Body - **template_id** (integer) - Required - ID of the OS template to install. - **password** (string) - Optional - The new strong password for the control panel. If omitted, a random one is generated. - **post_install_script_id** (integer) - Optional - ID of a script to run after installation. ### Request Example ```php $virtualMachineId = 1268054; $data = [ 'template_id' => 1130, // ID of the OS template to install 'password' => 'AnotherStr0ngP@ss!', // Optional: If omitted, a random one is generated 'post_install_script_id' => 6324, // Optional: ID of a script to run after install ]; $action = $hostinger->vps()->virtualMachines()->recreate($virtualMachineId, $data); ``` ### Response #### Success Response (200) - **id** (integer) - The action ID. - **name** (string) - The name of the action. - **state** (string) - The state of the action (e.g., 'success'). - **created_at** (string) - The timestamp when the action was created. - **updated_at** (string) - The timestamp when the action was last updated. #### Response Example ```json { "id": 8123727, "name": "recreate", "state": "success", "created_at": "2025-04-01 10:00:00", "updated_at": "2025-04-01 10:05:00" } ``` ``` -------------------------------- ### Restart Virtual Machine Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Restarts a virtual machine. This action is equivalent to stopping and then starting the VM. It can also be used to start a VM that is currently stopped. ```php $virtualMachineId = 1268054; $action = $hostinger->vps()->virtualMachines()->restart($virtualMachineId); $action->id; // 8123712 $action->name; // restart $action->state->value; // success $action->created_at->format('Y-m-d H:i:s'); // 2025-02-27 11:54:00 $action->updated_at->format('Y-m-d H:i:s'); // 2025-02-27 11:58:00 $action->toArray(); // ['id' => 8123712, 'name' => 'restart', 'state' => 'success', ...] ``` -------------------------------- ### Get Catalog Item List Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Retrieves a list of catalog items. Prices are in cents and can be filtered by category or name. Use the `toArray()` method to get a multidimensional array representation. ```php // Get all items $catalogs = $hostinger->billing()->catalog()->list(); // Get only VPS items $vpsCatalogs = $hostinger->billing()->catalog()->list(['category' => 'VPS']); // Get only .COM domain items $comCatalogs = $hostinger->billing()->catalog()->list(['name' => '.COM*']); foreach ($catalogs as $catalog) { $catalog->id; // hostingercom-vps-kvm2 $catalog->name; // KVM 2 $catalog->category; // VPS foreach ($catalog->prices as $price) { $price->id; // hostingercom-vps-kvm2-usd-1m $price->name; // KVM 2 (billed every month) $price->currency; // USD $price->price; // 1799 (cents) $price->first_period_price; // 899 (cents) $price->period; // 1 $price->period_unit->value; // month, year, day, week, none $price->toArray(); // ['id' => '...', 'name' => '...', 'currency' => 'USD', ...] } $catalog->toArray(); // ['id' => '...', 'name' => 'KVM 2', 'category' => 'VPS', 'prices' => [[...], ...]] } ``` -------------------------------- ### GET /api/vps/v1/firewall Source: https://github.com/derrickobedgiu1/hostinger-php-sdk/blob/main/README.md Retrieves a paginated list of all firewalls available in your account. ```APIDOC ## Get Firewall List ### Description Retrieves a paginated list of all firewalls available in your account. ### Method GET ### Endpoint /api/vps/v1/firewall ### Parameters #### Query Parameters - **page** (integer) - Optional - The page number to retrieve. - **per_page** (integer) - Optional - The number of items per page. ### Request Example ```php $firewallsPage = $hostinger->vps()->firewalls()->list(['page' => 1]); ``` ### Response #### Success Response (200) - **data** (array) - An array of firewall objects. - **id** (integer) - The ID of the firewall. - **name** (string) - The name of the firewall. - **is_synced** (boolean) - Indicates if the firewall configuration is synced. - **created_at** (datetime) - The timestamp when the firewall was created. - **updated_at** (datetime) - The timestamp when the firewall was last updated. - **rules** (array) - An array of firewall rules. - **meta** (object) - Pagination metadata. - **current_page** (integer) - The current page number. - **per_page** (integer) - The number of items per page. - **total** (integer) - The total number of items. #### Response Example ```json { "data": [ { "id": 65224, "name": "HTTP and SSH only", "is_synced": false, "created_at": "2021-09-01 12:00:00", "updated_at": "2021-09-01 12:00:00", "rules": [ { "id": 24541, "action": "accept", "protocol": "TCP", "port": "1024:2048", "source": "any", "source_detail": "any" } ] } ], "meta": { "current_page": 1, "per_page": 15, "total": 100 } } ``` ```