### Install MyOwnFreeHost API Client with Composer Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md Install the library using Composer. This is the recommended method for managing dependencies. ```bash composer require infinityfree/mofh-client ``` -------------------------------- ### Example: Create Account and Get Username Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/response-objects.md Demonstrates how to call the createAccount method and then retrieve the VistaPanel username from the response if the operation was successful. ```php $response = $client->createAccount( 'abcd1234', 'password', 'user@example.com', 'domain.com', 'plan' ); if ($response->isSuccessful()) { $vpUsername = $response->getVpUsername(); echo "Created: " . $vpUsername; } ``` -------------------------------- ### ListPackagesResponse Example Usage Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/types-and-structures.md Demonstrates iterating through packages obtained from ListPackagesResponse and displaying their details. ```php $response = $client->listPackages(); if ($response->isSuccessful()) { foreach ($response->getPackages() as $package) { echo $package['name'] . "\n"; echo " Disk: " . $package['QUOTA'] . "MB\n"; echo " Bandwidth: " . $package['BWLIMIT'] . "MB\n"; } } ``` -------------------------------- ### Create Ticket Response Example Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/response-objects.md Example of how to handle the response from the createTicket method. Checks if the ticket was successful and retrieves the ticket ID. ```php public function getTicketId(): ?string { return $this->data['ticket_id'] ?? null; } ``` ```php $response = $client->createTicket( 'Subject', 'Message', 'domain.com', 'user_12345678', '192.168.1.1' ); if ($response->isSuccessful()) { echo "Ticket #" . $response->getTicketId(); } ``` -------------------------------- ### GetUserDomainsResponse Example Usage Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/types-and-structures.md Example of how to retrieve and process domain information from a GetUserDomainsResponse, including handling potential exceptions for mismatched statuses. ```php $response = $client->getUserDomains('user_12345678'); $domains = $response->getDomains(); // Returns ['domain1.com', 'domain2.com', 'domain3.com'] try { $status = $response->getStatus(); // Returns 'ACTIVE' or 'SUSPENDED' if consistent } catch (MismatchedStatusesException $e) { // Domains have different statuses } ``` -------------------------------- ### Initialize MOFH Client with Optional Parameters Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md This example shows how to initialize the MOFH Client with optional custom API URL and an HTTP client instance. This is useful for advanced configurations or testing. ```php $client = new Client( $apiUsername, $apiPassword, 'https://panel.myownfreehost.net', // custom API URL $guzzleClient // custom HTTP client ); ``` -------------------------------- ### GetDomainUserResponse Example Usage Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/types-and-structures.md Demonstrates how to use the GetDomainUserResponse object to check if a domain user was found and retrieve their details. ```php $response = $client->getDomainUser('example.com'); if ($response->isFound()) { // $response->getUsername() returns 'host_12345678' // $response->getStatus() returns 'ACTIVE' or 'SUSPENDED' // $response->getDocumentRoot() returns '/home/vol_x/epizy.com/host_12345678/example.com/htdocs' } ``` -------------------------------- ### CreateTicketResponse Parsing Example Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/types-and-structures.md Illustrates how to extract the ticket ID from a successful CreateTicketResponse. ```php // Input: 'SUCCESS:12345' // getTicketId() returns: '12345' ``` -------------------------------- ### Install MOFH Client with Composer Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/configuration.md Adds the MOFH Client package to your project's dependencies using Composer. This command should be run in your project's root directory. ```json { "require": { "infinityfree/mofh-client": "^1.0" } } ``` ```bash composer require infinityfree/mofh-client ``` -------------------------------- ### XML Error Format Example Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/types-and-structures.md Represents the structure of an error response in XML format. Used when an operation fails and the response is expected to be XML. ```php [ 'result' => [ 'status' => '0', 'statusmsg' => 'Error description here' ] ] ``` -------------------------------- ### PHP Requirements for MOFH Client Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/configuration.md Specifies the PHP version and required extensions for the MOFH Client library, as defined in composer.json. Ensure these are met before installation. ```json { "require": { "php": ">=7.3", "ext-json": "*", "ext-libxml": "*", "ext-simplexml": "*", "guzzlehttp/guzzle": "~6.0|~7.0" } } ``` -------------------------------- ### Plain Text Error Format Example Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/types-and-structures.md Represents an error response in plain text format. Used for simple error messages where structured data is not necessary. ```text 'Error message text' ``` -------------------------------- ### Handling HTTP Communication Errors Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/exceptions.md This example demonstrates how to catch specific HTTP communication errors using MofhClientHttpException. It includes initializing the client and making an API call within a try-catch block. ```php use InfinityFree\MofhClient\Client; use InfinityFree\MofhClient\Exception\MofhClientHttpException; $client = new Client('api_user', 'api_pass'); try { $response = $client->createAccount( 'user1234', 'password', 'user@example.com', 'example.com', 'plan' ); // Check API-level success (not exception) if (!$response->isSuccessful()) { echo "API Error: " . $response->getMessage(); } } catch (MofhClientHttpException $e) { echo "HTTP Communication Error: " . $e->getMessage(); // Log error, retry with backoff, etc. } ``` -------------------------------- ### Get Domain User Information Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Fetch account details for a specific domain, including its status, document root, and associated username. Returns null or an empty array if the domain is not found. ```php $response = $client->getDomainUser('example.com'); if ($response->isFound()) { echo "Account: " . $response->getUsername() . "\n"; echo "Status: " . $response->getStatus() . "\n"; echo "Root: " . $response->getDocumentRoot(); } else { echo "Domain not found"; } ``` -------------------------------- ### Initialize MyOwnFreeHost API Client Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md Instantiate the API client with your MyOwnFreeHost API username and password. Ensure you have obtained these credentials from the reseller panel. ```php use InfinityFree\MofhClient\Client; $client = new Client("", ""); ``` -------------------------------- ### Create and Manage Hosting Account Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md This snippet demonstrates the workflow for creating a new hosting account, retrieving its associated domains, and looking up specific domain information. Ensure you have valid account credentials and plan details. ```php // 1. Create account $create = $client->createAccount( 'user1234', 'pass', 'email@example.com', 'domain.com', 'plan' ); if ($create->isSuccessful()) { $vpUsername = $create->getVpUsername(); // "user1_12345678" } // 2. Get domains on account $domains = $client->getUserDomains($vpUsername); if ($domains->isSuccessful()) { foreach ($domains->getDomains() as $domain) { echo $domain; } } // 3. Look up specific domain $info = $client->getDomainUser('domain.com'); if ($info->isFound()) { echo "Root: " . $info->getDocumentRoot(); } ``` -------------------------------- ### PHP Protected GET Request Signature Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/client.md Signature for sending an authenticated GET request to the API with query parameters. Requires path, parameters, and an optional timeout. ```php protected function sendGetRequest( string $path, array $parameters, float $timeout = 10.0 ): ResponseInterface ``` -------------------------------- ### Account Creation Workflow Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md Demonstrates the process of creating a new hosting account, retrieving its associated domains, and looking up specific domain information. ```APIDOC ## Account Creation Workflow ### Description This workflow shows how to create a new hosting account, retrieve the domains associated with that account, and get information about a specific domain. ### Methods - `createAccount(username, password, email, domain, plan)`: Creates a new hosting account. - `getUserDomains(vpUsername)`: Retrieves a list of domains for a given virtual private username. - `getDomainUser(domain)`: Looks up information for a specific domain. ### Usage Example ```php // 1. Create account $create = $client->createAccount( 'user1234', 'pass', 'email@example.com', 'domain.com', 'plan' ); if ($create->isSuccessful()) { $vpUsername = $create->getVpUsername(); // "user1_12345678" } // 2. Get domains on account $domains = $client->getUserDomains($vpUsername); if ($domains->isSuccessful()) { foreach ($domains->getDomains() as $domain) { echo $domain; } } // 3. Look up specific domain $info = $client->getDomainUser('domain.com'); if ($info->isFound()) { echo "Root: " . $info->getDocumentRoot(); } ``` ``` -------------------------------- ### Create Hosting Account Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/client.md Creates a new hosting account on MyOwnFreeHost. Requires username, password, email, domain, and plan. Returns a CreateAccountResponse object. ```php public function createAccount( string $username, string $password, string $email, string $domain, string $plan ): CreateAccountResponse ``` ```php $response = $client->createAccount( 'abcd1234', 'SecurePass123!', 'user@example.com', 'mydomain.example.com', 'free_plan' ); if ($response->isSuccessful()) { echo "Account created: " . $response->getVpUsername(); } else { echo "Error: " . $response->getMessage(); } ``` -------------------------------- ### List Available Hosting Packages Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md Retrieve a list of available hosting packages. The response includes details like disk quota and bandwidth limit for each package. ```php $response = $client->listPackages(); if ($response->isSuccessful()) { foreach ($response->getPackages() as $package) { echo $package['name'] . ": " . $package['QUOTA'] . " MB disk, " . $package['BWLIMIT'] . " MB bandwidth\n"; } } ``` -------------------------------- ### Get CNAME Record Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Retrieves the CNAME record required for domain verification. Returns the CNAME value on success or an error message. ```APIDOC ## POST /xml-api/getcname ### Description Gets the CNAME record for domain verification. ### Method POST ### Endpoint /xml-api/getcname ### Parameters #### Request Body - **api_user** (string) - Yes - API username - **api_key** (string) - Yes - API password - **domain_name** (string) - Yes - Domain name ### Response #### Success Response - **cname** (string) - The CNAME value for domain verification. #### Error Response - **error** (string) - An error message prefixed with 'ERROR:'. ### Response Example (Success) ``` subdomain.verifydomaininmotion.com ``` ### Response Example (Error) ``` ERROR:Invalid domain name provided ``` ``` -------------------------------- ### Create Hosting Account Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md Demonstrates how to create a new hosting account using the MOFH client. Ensure you have your API credentials and the desired account details ready. Handles potential HTTP exceptions during the process. ```php use InfinityFree\MofhClient\Client; use InfinityFree\MofhClient\Exception\MofhClientHttpException; // Initialize client $client = new Client('api_username', 'api_password'); // Account Operations try { $response = $client->createAccount( 'abcd1234', 'password', 'user@example.com', 'example.com', 'free_plan' ); if ($response->isSuccessful()) { echo "Account: " . $response->getVpUsername(); } else { echo "Error: " . $response->getMessage(); } } catch (MofhClientHttpException $e) { echo "HTTP Error: " . $e->getMessage(); } ``` -------------------------------- ### Get Domain User Information Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Retrieves account information for a given domain, including its status, document root, and associated username. ```APIDOC ## GET /json-api/getdomainuser ### Description Gets account information for a domain. ### Method GET ### Endpoint /json-api/getdomainuser ### Parameters #### Query Parameters - **domain** (string) - Yes - Domain name to look up - **api_user** (string) - Yes - API username - **api_key** (string) - Yes - API password ### Response #### Success Response - **account_info** (array) - If found, a 4-element array: [status, domain, document_root, username]. Status can be "ACTIVE" or "SUSPENDED". - **account_info** (null) - If not found. ### Response Example (Found) ```json ["ACTIVE", "domain.com", "/home/vol_x/example.com/host_12345678/domain.com/htdocs", "host_12345678"] ``` ### Response Example (Not Found) ``` null ``` ``` -------------------------------- ### Get User Domains Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Retrieves a list of all domains associated with a specific user account. Returns an array of domain status and names. ```APIDOC ## GET /json-api/getuserdomains ### Description Gets domains linked to an account. ### Method GET ### Endpoint /json-api/getuserdomains ### Parameters #### Query Parameters - **username** (string) - Yes - VistaPanel username (e.g., test_12345678) - **api_user** (string) - Yes - API username - **api_key** (string) - Yes - API password ### Response #### Success Response - **domains** (array) - Array of [status, domain_name] pairs. Status can be "ACTIVE" or "SUSPENDED". ### Response Example ```json [ ["ACTIVE", "domain1.com"], ["ACTIVE", "domain2.com"], ["SUSPENDED", "domain3.com"] ] ``` ``` -------------------------------- ### Create Account Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Creates a new hosting account with specified details. This endpoint is used for provisioning new user accounts on the MyOwnFreeHost platform. ```APIDOC ## POST /xml-api/createacct ### Description Creates a new hosting account. ### Method POST ### Endpoint /xml-api/createacct ### Parameters #### Request Body - **username** (string) - Required - Custom 8-character account username (letters/numbers) - **password** (string) - Required - Control panel and FTP password - **contactemail** (string) - Required - Account owner's email address - **domain** (string) - Required - Primary domain or subdomain - **plan** (string) - Required - Hosting plan name (must be configured in MOFH) ### Response #### Success Response (status: 1) - **result.options.vpusername** (string) - The username for the created account (e.g., "test_12345678") #### Error Response - **result.statusmsg** (string) - Error message if creation fails ### Request Example ```php $response = $client->createAccount( 'abcd1234', 'MyPassword123!', 'user@example.com', 'example.com', 'free_plan' ); if ($response->isSuccessful()) { $vpUsername = $response->getVpUsername(); // "abcd_12345678" } else { echo $response->getMessage(); } ``` ``` -------------------------------- ### JSON Error Format Example Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/types-and-structures.md Represents the structure of an error response in JSON format. Used when an operation fails and the response is expected to be JSON. ```php [ 'cpanelresult' => [ 'error' => 'Error description here' ] ] ``` -------------------------------- ### Create a Hosting Account Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md Use this snippet to create a new hosting account. Ensure you have your API credentials and account details ready. ```php use InfinityFree\MofhClient\Client; $client = new Client("", ""); $response = $client->createAccount( 'abcd1234', 'password123', 'user@example.com', 'userdomain.example.com', 'my_plan' ); if ($response->isSuccessful()) { echo "Created account with username: " . $response->getVpUsername(); } else { echo "Failed to create account: " . $response->getMessage(); } ``` -------------------------------- ### Create Hosting Account Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Use this method to create a new hosting account. Ensure you provide a valid username, password, contact email, domain, and a pre-configured hosting plan. ```php $response = $client->createAccount( 'abcd1234', 'MyPassword123!', 'user@example.com', 'example.com', 'free_plan' ); if ($response->isSuccessful()) { $vpUsername = $response->getVpUsername(); // "abcd_12345678" } else { echo $response->getMessage(); } ``` -------------------------------- ### Basic Client Constructor Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/configuration.md Instantiate the MOFH Client with essential API credentials and optional parameters like the API URL and an HTTP client instance. ```php $client = new Client( string $apiUsername, string $apiPassword, string $apiUrl = 'https://panel.myownfreehost.net', ?ClientInterface $httpClient = null ) ``` -------------------------------- ### Get CNAME Record Response Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/response-objects.md Handles responses from the `getCname()` method. Use `isSuccessful()` to check for errors and `getCname()` to retrieve the CNAME value. ```php public function getCname(): ?string ``` ```php $response = $client->getCname('example.com'); if ($response->isSuccessful()) { echo "Add this CNAME record: " . $response->getCname(); } else { echo "Error: " . $response->getMessage(); } ``` -------------------------------- ### ListPackagesResponse Accessor Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md Retrieves a list of available hosting packages. ```php $response->getPackages(): ?array ``` -------------------------------- ### Get User Domains Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Retrieve a list of all domains associated with a user account. The response is a JSON array where each element is a pair of [status, domain_name]. ```php $response = $client->getUserDomains('test_12345678'); if ($response->isSuccessful()) { foreach ($response->getDomains() as $domain) { echo $domain . "\n"; } try { $status = $response->getStatus(); // throws if inconsistent } catch (MismatchedStatusesException $e) { // domains have different statuses } } ``` -------------------------------- ### Run Tests with Composer or PHPUnit Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/configuration.md Execute the test suite using the 'composer test' command or directly via the PHPUnit executable. ```bash composer test # or vendor/bin/phpunit ``` -------------------------------- ### List Hosting Packages Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Retrieves a list of available hosting packages. Use this to display package options to users or for administrative purposes. ```php $response = $client->listPackages(); if ($response->isSuccessful()) { foreach ($response->getPackages() as $pkg) { echo $pkg['name'] . ": " . $pkg['QUOTA'] . "MB - " . $pkg['BWLIMIT'] . "MB bandwidth\n"; } } ``` -------------------------------- ### PasswordResponse Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/response-objects.md Represents the response from a password change operation. It provides methods to check for success, retrieve messages, and get the account status if the operation failed. ```APIDOC ## PasswordResponse Response from `Client::password()`. ### Methods #### isSuccessful() Returns whether password change succeeded. **Returns:** `bool` **Note:** Setting an identical password is treated as successful. --- #### getMessage() Returns error message or null. **Returns:** `string|null` --- #### getStatus() ```php public function getStatus(): ?string ``` Returns the account status if the password change failed. Status codes: - `a` — active - `x` — suspended - `r` — reactivating - `c` — closing **Returns:** `string|null` — Status code or null --- ``` -------------------------------- ### SuspendResponse Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/response-objects.md Represents the response from the Client::suspend() method. It provides methods to check the success of the suspension, retrieve status messages, and get details about the suspension. ```APIDOC ## SuspendResponse Response from `Client::suspend()`. ### Methods #### isSuccessful() Returns whether account suspension succeeded. **Returns:** `bool` --- #### getMessage() Returns error message or null. **Returns:** `string|null` --- #### getVpUsername() ```php public function getVpUsername(): ?string ``` Returns the VistaPanel username if the account is already suspended. **Returns:** `string|null` — VistaPanel username or null --- #### getStatus() ```php public function getStatus(): ?string ``` Returns the account status if it is not active. Status codes: - `x` — suspended - `r` — reactivating - `c` — closing **Returns:** `string|null` — Status code or null --- #### getReason() ```php public function getReason(): ?string ``` Returns the suspension reason if the account is already suspended. **Returns:** `string|null` — Suspension reason or null --- ``` -------------------------------- ### Configure MOFH Client with Environment Variables Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/configuration.md Instantiate the MOFH client using credentials stored in environment variables. Ensure MOFH_API_USERNAME, MOFH_API_PASSWORD, and optionally MOFH_API_URL are set. ```php $client = new Client( $_ENV['MOFH_API_USERNAME'], $_ENV['MOFH_API_PASSWORD'], $_ENV['MOFH_API_URL'] ?? 'https://panel.myownfreehost.net' ); ``` -------------------------------- ### PHP HTTP Error Handling with MofhClientHttpException Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/client.md Example of how to catch MofhClientHttpException for network errors or timeouts when using the MOFH client. API-level errors are handled separately. ```php use InfinityFree\MofhClient\Exception\MofhClientHttpException; try { $response = $client->createAccount(...); } catch (MofhClientHttpException $e) { echo "HTTP Error: " . $e->getMessage(); } ``` -------------------------------- ### Initialize MOFH Client with Required Parameters Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md Use this snippet to create a new MOFH Client instance with only the essential API username and password. Ensure these credentials are kept secure. ```php $client = new Client( $apiUsername, // string, required $apiPassword // string, required ); ``` -------------------------------- ### Create and Reply to Support Ticket Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md This snippet illustrates the process of creating a new support ticket and subsequently replying to it. Ensure you have the correct ticket ID, user details, and IP address for accurate ticket management. ```php // Create ticket $create = $client->createTicket( 'Subject here', 'Ticket body', 'domain.com', 'user_12345678', '192.168.1.1' ); if ($create->isSuccessful()) { $ticketId = $create->getTicketId(); // Reply to ticket $reply = $client->replyTicket( $ticketId, 'Reply message', 'user_12345678', '192.168.1.1' ); if ($reply->isSuccessful()) { echo "Reply added"; } } ``` -------------------------------- ### Client Constructor Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/client.md Creates a new Client instance for API communication. It requires API credentials and optionally accepts a custom API URL and HTTP client. ```APIDOC ## Client Constructor ### Description Creates a new Client instance for API communication. It requires API credentials and optionally accepts a custom API URL and HTTP client. ### Signature ```php public function __construct(string $apiUsername, string $apiPassword, ?string $apiUrl = 'https://panel.myownfreehost.net', ?ClientInterface $httpClient = null): void ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | apiUsername | string | Yes | — | The API Username from MyOwnFreeHost reseller panel | | apiPassword | string | Yes | — | The API Password from MyOwnFreeHost reseller panel | | apiUrl | string | No | `https://panel.myownfreehost.net` | Base URL of MyOwnFreeHost API. Trailing slashes and `/xml-api` suffix are automatically stripped | | httpClient | ClientInterface|null | No | null | Custom Guzzle HTTP client instance. If null, creates a default client with 5-second connection timeout | ### Request Example ```php use InfinityFree\MofhClient\Client; // Basic initialization $client = new Client('api_username', 'api_password'); // With custom HTTP client $guzzleClient = new \GuzzleHttp\Client(); $client = new Client('api_username', 'api_password', 'https://panel.myownfreehost.net', $guzzleClient); ``` ### Response #### Success Response None (Constructor does not return a value) #### Response Example None ### Throws No exceptions from constructor ``` -------------------------------- ### Get VistaPanel Username from Create Account Response Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/response-objects.md The CreateAccountResponse object provides getVpUsername() to retrieve the username of the newly created account. This is useful after a successful account creation. ```php public function getVpUsername(): ?string ``` -------------------------------- ### Import MOFH Client Classes Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/configuration.md Demonstrates how to import the main Client class and a specific exception class from the MOFH Client library. These use statements are required at the beginning of your PHP files. ```php use InfinityFree\MofhClient\Client; use InfinityFree\MofhClient\Exception\MofhClientHttpException; ``` -------------------------------- ### Get CNAME Record for Domain Verification Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Obtain the CNAME record required for domain verification. The response is either the CNAME value or an error message prefixed with 'ERROR'. ```php $response = $client->getCname('example.com'); if ($response->isSuccessful()) { echo "Add this CNAME: " . $response->getCname(); } ``` -------------------------------- ### createAccount Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md Creates a new hosting account with specified details. ```APIDOC ## createAccount ### Description Create a new hosting account. ### Method Not specified (assumed to be a client method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **username** (string) - Required - A unique, 8 character identifier of the account. - **password** (string) - Required - A password to login to the control panel, FTP and databases. - **email** (string) - Required - The email address of the user. - **domain** (string) - Required - A domain name to create the account. Can be a subdomain or a custom domain. - **plan** (string) - Required - The name of the hosting plan to create the account on. Requires a hosting package to be configured through MyOwnFreeHost. ### Request Example None specified ### Response #### Success Response None specified #### Response Example None specified ``` -------------------------------- ### listPackages Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md Retrieves a list of available hosting packages from your reseller account. ```APIDOC ## listPackages ### Description Get a list of available hosting packages from your reseller account. ### Method Not specified (assumed to be a client method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None specified ### Response #### Success Response None specified #### Response Example None specified ``` -------------------------------- ### Package Methods Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md Methods for retrieving information about available hosting packages or plans. ```APIDOC ## Packages ### `listPackages()` #### Description Lists all available hosting packages or plans. #### Method `listPackages()` #### Returns `ListPackagesResponse` ``` -------------------------------- ### List Packages Response Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/response-objects.md Handles responses from the `listPackages()` method. Use `isSuccessful()` to check for errors and `getPackages()` to iterate through available hosting packages. ```php public function getPackages(): ?array ``` ```php $response = $client->listPackages(); if ($response->isSuccessful()) { foreach ($response->getPackages() as $pkg) { echo $pkg['name'] . " - " . $pkg['QUOTA'] . "MB disk - " . $pkg['BWLIMIT'] . "MB bandwidth\n"; } } ``` -------------------------------- ### Initialize MOFH Client Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/client.md Instantiate the Client class for API communication. Basic initialization requires only API credentials. A custom HTTP client can also be provided. ```php use InfinityFree\MofhClient\Client; // Basic initialization $client = new Client('api_username', 'api_password'); // With custom HTTP client $guzzleClient = new \GuzzleHttp\Client(); $client = new Client('api_username', 'api_password', 'https://panel.myownfreehost.net', $guzzleClient); ``` -------------------------------- ### Change Hosting Package Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Use the `changePackage` method to update an account's hosting plan. Ensure you provide a valid username and package name. ```php $response = $client->changePackage('abcd1234', 'premium_plan'); if ($response->isSuccessful()) { echo "Package updated"; } ``` -------------------------------- ### Create a Support Ticket Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md Use this code to create a new support ticket. Provide a subject, detailed message, associated domain, account username, and the user's IP address. ```php $response = $client->createTicket( 'Cannot access my website', 'I am getting a 500 error when I try to visit my website.', 'userdomain.example.com', 'abcd_12345678', '192.168.1.1' ); if ($response->isSuccessful()) { echo "Ticket created with ID: " . $response->getTicketId(); } else { echo "Failed to create ticket: " . $response->getMessage(); } ``` -------------------------------- ### changePackage Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md Changes the hosting package of an account. ```APIDOC ## changePackage ### Description Change the hosting package of an account. ### Method Not specified (assumed to be a client method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **username** (string) - Required - The unique, 8 character identifier of the account. - **package** (string) - Required - The name of the new hosting package to assign. ### Request Example None specified ### Response #### Success Response None specified #### Response Example None specified ``` -------------------------------- ### availability() Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/client.md Checks if a domain name is available for use on MyOwnFreeHost. ```APIDOC ## availability() ### Description Checks if a domain name is available for use on MyOwnFreeHost. ### Method GET (assumed, based on operation) ### Endpoint `/availability` (assumed, based on operation) ### Parameters #### Path Parameters None #### Query Parameters - **domain** (string) - Required - Domain name or subdomain to check ### Request Example ```php $response = $client->availability('newdomain.example.com'); if ($response->isAvailable()) { echo "Domain is available!"; } else { echo "Domain is already in use"; } ``` ### Response #### Success Response (200) - **AvailabilityResponse** (object) - Object containing the availability status of the domain. #### Response Example ```json { "isAvailable": true } ``` **Throws:** `MofhClientHttpException` if HTTP communication fails ``` -------------------------------- ### List Hosting Packages Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Retrieves a list of all available hosting packages offered by MOFH. This endpoint is useful for understanding the different plans and their configurations. ```APIDOC ## GET /json-api/listpkgs ### Description Lists available hosting packages. ### Method GET ### Endpoint /json-api/listpkgs ### Parameters #### Query Parameters - **api_user** (string) - Yes - (added by client) API username - **api_key** (string) - Yes - (added by client) API password ### Response #### Success Response (200) - **packages** (array) - Array of package objects with name, QUOTA, BWLIMIT, etc. ### Response Example ```json { "packages": [ { "name": "free_plan", "QUOTA": "1024", "BWLIMIT": "10240", "...": "..." } ] } ``` ``` -------------------------------- ### POST /xml-api/changepackage Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Changes the hosting package of an account. This operation requires the custom username and the desired new package name. ```APIDOC ## POST /xml-api/changepackage ### Description Changes the hosting package of an account. ### Method POST ### Endpoint /xml-api/changepackage ### Parameters #### Request Body - **user** (string) - Required - Custom 8-character username - **pkg** (string) - Required - Package name (converted to lowercase) ### Response #### Success Response (200) - **result.status** (integer) - Indicates success (1 for success) - **result.statusmsg** (string) - Success or error message ### Request Example ```php $response = $client->changePackage('abcd1234', 'premium_plan'); if ($response->isSuccessful()) { echo "Package updated"; } ``` ``` -------------------------------- ### changePackage() Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/client.md Upgrades or downgrades the hosting package of an account. ```APIDOC ## changePackage() ### Description Upgrades or downgrades the hosting package of an account. ### Method PUT (inferred from package change operation) ### Endpoint /accounts/{username}/package ### Parameters #### Path Parameters - **username** (string) - Required - Custom 8-character username #### Query Parameters None #### Request Body - **package** (string) - Required - Name of new hosting package to assign (converted to lowercase) ### Request Example ```php { "package": "premium_plan" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success or failure of the operation. #### Response Example ```json { "status": "success" } ``` **Throws:** `MofhClientHttpException` if HTTP communication fails ``` -------------------------------- ### Suspend and Remove a Hosting Account Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md This snippet demonstrates how to first suspend an account and then remove it. It includes error handling for both operations. ```php // First suspend the account $suspendResponse = $client->suspend('abcd1234', 'User requested account deletion'); if (!$suspendResponse->isSuccessful()) { die("Failed to suspend: " . $suspendResponse->getMessage()); } // Then remove it $removeResponse = $client->removeAccount('abcd1234'); if ($removeResponse->isSuccessful()) { echo "Account removed successfully"; } else { echo "Failed to remove account: " . $removeResponse->getMessage(); } ``` -------------------------------- ### Catch MismatchedStatusesException Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/exceptions.md Demonstrates how to catch a MismatchedStatusesException when retrieving user domains, indicating conflicting status values among domains. Includes a fallback to retrieve individual domain information. ```php $response = $client->getUserDomains('user_12345678'); try { $status = $response->getStatus(); // $status contains the single status if all domains match } catch (MismatchedStatusesException $e) { // Some domains have ACTIVE status, others have SUSPENDED status echo "Error: " . $e->getMessage(); // Fallback: get individual domain information $domains = $response->getDomains(); } ``` -------------------------------- ### Retrieve Domain User Details Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/response-objects.md After confirming a domain is found using isFound(), retrieve the hosting account username, document root path, and account status. This snippet demonstrates accessing multiple details from the response. ```php public function getUsername(): ?string ``` ```php public function getStatus(): ?string ``` ```php public function getDomain(): ?string ``` ```php public function getDocumentRoot(): ?string ``` ```php $response = $client->getDomainUser('example.com'); if ($response->isFound()) { echo "Hosting Account: " . $response->getUsername() . "\n"; echo "Root: " . $response->getDocumentRoot() . "\n"; echo "Status: " . $response->getStatus(); } ``` -------------------------------- ### Configure MOFH Client with a Configuration File Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/configuration.md Load API credentials from a PHP configuration file. This method is useful for managing sensitive information separately from your application code. ```php // config/mofh.php return [ 'api_username' => 'your_api_username', 'api_password' => 'your_api_password', 'api_url' => 'https://panel.myownfreehost.net', ]; // usage $config = require 'config/mofh.php'; $client = new Client( $config['api_username'], $config['api_password'], $config['api_url'] ); ``` -------------------------------- ### Handling Status Mismatch with getUserDomains Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/exceptions.md An alternative approach to handling user domain statuses, showing how to gracefully manage MismatchedStatusesException or directly retrieve the list of domains if statuses differ. ```php try { $response = $client->getUserDomains('user_12345678'); if ($response->isSuccessful()) { try { $status = $response->getStatus(); echo "Account Status: " . $status; } catch (MismatchedStatusesException $e) { echo "Domains have different statuses"; // Alternative: Don't call getStatus() // Just get the domains list instead $domains = $response->getDomains(); } } } catch (MofhClientHttpException $e) { echo "HTTP Error: " . $e->getMessage(); } ``` -------------------------------- ### ListPackagesResponse Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/response-objects.md Represents the response from the Client::listPackages() method, which uses a JSON payload. ```APIDOC ## ListPackagesResponse Response from `Client::listPackages()`. ### Methods #### isSuccessful() Returns whether the request succeeded. **Returns:** `bool` --- #### getMessage() Returns error message or null. **Returns:** `string|null` --- #### getPackages() ```php public function getPackages(): ?array ``` Returns array of available hosting packages. **Returns:** `array|null` — Array of package objects with keys: `name`, `QUOTA`, `BWLIMIT`, etc., or null on error **Example:** ```php $response = $client->listPackages(); if ($response->isSuccessful()) { foreach ($response->getPackages() as $pkg) { echo $pkg['name'] . " - " . $pkg['QUOTA'] . "MB disk - " . $pkg['BWLIMIT'] . "MB bandwidth\n"; } } ``` --- ``` -------------------------------- ### ListPackagesResponse Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/types-and-structures.md Represents the response from a package list query, containing an array of available packages. ```APIDOC ## ListPackagesResponse ### Description Response from package list query. ### Data Structure ```php [ 'packages' => [ [ 'name' => 'free_plan', 'QUOTA' => '1024', // Disk quota in MB 'BWLIMIT' => '10240', // Bandwidth limit in MB // ... other fields ], // ... more packages ] ] ``` ### Methods - `isSuccessful(): bool` — Returns true if no cpanelresult.error - `getMessage(): ?string` — Returns error or null - `getPackages(): ?array` — Returns array of package objects ### Package Object Structure ```php [ 'name' => string, // Package identifier 'QUOTA' => string, // Disk space in MB 'BWLIMIT' => string, // Bandwidth in MB // Additional fields vary by configuration ] ``` ### Example ```php $response = $client->listPackages(); if ($response->isSuccessful()) { foreach ($response->getPackages() as $package) { echo $package['name'] . "\n"; echo " Disk: " . $package['QUOTA'] . "MB\n"; echo " Bandwidth: " . $package['BWLIMIT'] . "MB\n"; } } ``` ``` -------------------------------- ### unsuspend Source: https://github.com/infinityfreehosting/mofh-client/blob/master/README.md Reactivates a hosting account. ```APIDOC ## unsuspend ### Description Reactivate a hosting account. ### Method Not specified (assumed to be a client method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **username** (string) - Required - The unique, 8 character identifier of the account. ### Request Example None specified ### Response #### Success Response None specified #### Response Example None specified ``` -------------------------------- ### Suspend and Remove Hosting Account Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md This snippet shows how to suspend a hosting account before removing it, which is a required step. Verify the username before proceeding with suspension and removal. ```php // 1. Suspend first (required before removal) $suspend = $client->suspend('user1_12345678', 'User requested deletion'); if (!$suspend->isSuccessful()) { die("Suspend failed: " . $suspend->getMessage()); } // 2. Remove account $remove = $client->removeAccount('user1_12345678'); if ($remove->isSuccessful()) { echo "Account removed"; } ``` -------------------------------- ### Account Management Methods Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/index.md Methods for managing hosting accounts, including creation, suspension, reactivation, password changes, plan modifications, and deletion. ```APIDOC ## Account Management ### `createAccount()` #### Description Creates a new hosting account with the specified details. #### Method `createAccount(string $username, string $password, string $email, string $domain, string $plan)` #### Returns `CreateAccountResponse` ### `suspend()` #### Description Suspends an existing hosting account. #### Method `suspend(string $username)` #### Returns `SuspendResponse` ### `unsuspend()` #### Description Reactivates a suspended hosting account. #### Method `unsuspend(string $username)` #### Returns `UnsuspendResponse` ### `password()` #### Description Changes the password for a hosting account. #### Method `password(string $username, string $newPassword)` #### Returns `PasswordResponse` ### `changePackage()` #### Description Changes the hosting plan for an account. #### Method `changePackage(string $username, string $newPlan)` #### Returns `ChangePackageResponse` ### `removeAccount()` #### Description Deletes a suspended hosting account. #### Method `removeAccount(string $username)` #### Returns `RemoveAccountResponse` ``` -------------------------------- ### Check Domain Availability Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Use this snippet to check if a domain name is available for registration. The response indicates availability with '1' for available and '0' for unavailable. ```php $response = $client->availability('example.com'); if ($response->isAvailable()) { echo "Available"; } else { echo "In use"; } ``` -------------------------------- ### Create Support Ticket Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md Creates a new support ticket with specified details. This is used when a user needs to submit a new issue or request. ```php $response = $client->createTicket( 'FTP Connection Issue', 'Cannot connect to FTP server', 'example.com', 'test_12345678', '192.168.1.1' ); if ($response->isSuccessful()) { echo "Ticket #" . $response->getTicketId(); } ``` -------------------------------- ### GetDomainUserResponse Data Structures Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/types-and-structures.md Illustrates the array format for domain user data when found and not found. ```php [ 0 => 'ACTIVE', // status 1 => 'example.com', // domain 2 => '/home/vol.../htdocs', // document_root 3 => 'host_12345678' // username ] ``` ```php [] // empty array ``` -------------------------------- ### Remove Hosting Account Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/api-endpoints.md To permanently delete a hosting account, it must first be suspended. Use `suspend` followed by `removeAccount`. Provide the username for both operations. ```php // Step 1: Suspend $suspend = $client->suspend('abcd1234', 'Deletion requested'); if (!$suspend->isSuccessful()) die("Suspend failed"); // Step 2: Remove $remove = $client->removeAccount('abcd1234'); if ($remove->isSuccessful()) { echo "Account deleted"; } ``` -------------------------------- ### MOFH API Endpoints Reference Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/README.md This section details the raw API endpoints available through the MyOwnFreeHost API. It includes information on HTTP methods, paths, authentication requirements, request parameters, and response formats (XML, JSON, plain text), along with success/failure indicators and error sources. ```APIDOC ## API Endpoints Reference This section provides a comprehensive reference to all 11 raw API endpoints offered by the MyOwnFreeHost API. For each endpoint, the following details are provided: ### HTTP Method and Path - The HTTP method (e.g., GET, POST, PUT, DELETE) used to access the endpoint. - The full endpoint path, including any necessary path parameters. ### Authentication - Information on the authentication mechanism required to access the endpoint. ### Request Parameters - A detailed list of all parameters required for the request, including their types and whether they are mandatory or optional. ### Response Formats - The expected response formats, which can include XML, JSON, or plain text. ### Success and Failure Indicators - Clear indicators for successful operations and failure conditions. ### Error Sources - Information on potential error sources and how they are reported by the API. ### Endpoint Request/Response Mapping - A complete mapping illustrating how requests are transformed into responses for each endpoint. ``` -------------------------------- ### Retrieve User Domains Source: https://github.com/infinityfreehosting/mofh-client/blob/master/_autodocs/client.md Retrieves all domains linked to a hosting account. Requires the VistaPanel username. Returns domain names and account status. ```php $response = $client->getUserDomains('abcd_12345678'); if ($response->isSuccessful()) { $domains = $response->getDomains(); foreach ($domains as $domain) { echo $domain . "\n"; } // Account status (same for all domains) echo "Status: " . $response->getStatus(); } else { echo "Error: " . $response->getMessage(); } ```