SOAP with PHP
Authentication, API requests, and response handling with PHP.
All KAS API functions can be called through SOAP requests. Use the API Reference to find the available functions and their parameters.
PHP SOAP client example
The following example shows authentication, API requests, and response handling.
-
KAS API authentication
For a small number of requests, you can use 'plain' authentication directly. For repeated requests, create a session token and use the 'session' authentication type.
<?php $parameters = [ 'kas_login' => 'w0123456', // KAS login 'kas_auth_type' => 'plain', 'kas_auth_data' => 'myPassword', // KAS password 'session_lifetime' => 600, // token lifetime in seconds 'session_update_lifetime' => 'Y', // extend the lifetime with every request 'session_2fa' => '123456', // one-time PIN if two-factor authentication is enabled ]; try { $client = new SoapClient('https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl'); $sessionToken = $client->KasAuth(json_encode($parameters)); echo "Session token: $sessionToken"; } catch (SoapFault $fault) { echo "Error code: {$fault->faultcode}\n"; echo "Message: {$fault->faultstring}\n"; } -
KAS API request
After successful authentication, the valid token is available in $sessionToken and can be used for KAS API requests.
Store the token in your application session so that authentication only needs to be performed once.
-
This example retrieves all domains for the login w0123456 with get_domains. The request does not require function parameters.
<?php $parameters = []; try { $client = new SoapClient('https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl'); $response = $client->KasApi(json_encode([ 'kas_login' => 'w0123456', // KAS login 'kas_auth_type' => 'session', // session authentication 'kas_auth_data' => $sessionToken, // session token 'kas_action' => 'get_domains', // API function 'KasRequestParams' => $parameters, // function parameters ])); } catch (SoapFault $fault) { echo "Error code: {$fault->faultcode}\n"; echo "Message: {$fault->faultstring}\n"; } -
This example creates a domain under the login w0123456 with add_domain.
<?php $parameters = [ 'domain_name' => 'example', 'domain_tld' => 'com', 'domain_path' => 'domain-path', 'redirect_status' => '0', ]; try { $client = new SoapClient('https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl'); $response = $client->KasApi(json_encode([ 'kas_login' => 'w0123456', // KAS login 'kas_auth_type' => 'session', // session authentication 'kas_auth_data' => $sessionToken, // session token 'kas_action' => 'add_domain', // API function 'KasRequestParams' => $parameters, // function parameters ])); } catch (SoapFault $fault) { echo "Error code: {$fault->faultcode}\n"; echo "Message: {$fault->faultstring}\n"; }
-
-
Response output
<?php echo '<pre>'; print_r($response); echo '</pre>';