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.
Scripts and automated tasks can also use an API key instead of the KAS password.
<?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>';
Authentication with an API key
An API key lets your scripts use the KAS API without your KAS password and without a session token. Create API keys in the KAS under Settings > KAS Password > API keys. A new key is displayed only once, directly after it has been created, so store it in a safe place.
Use the authentication type 'apikey' and pass the key as kas_auth_data. A key is valid for the login that created it and for all of its subaccounts, so kas_login can be that login or the login of one of its subaccounts.
- Two-factor authentication is not requested for API keys. Protect a key like a password.
- A new API key must be used for the first time within 24 hours, otherwise it expires. Afterwards, an API key expires if it has not been used for 90 days. Using the key extends its validity automatically.
- An API key cannot create session tokens (KasAuth) or login tokens, and it cannot change the KAS password, two-factor authentication or the password manager.
- API keys can only be created and deleted in the KAS, not through the KAS API.
- Requests with an invalid or expired key fail with kas_apikey_invalid or kas_apikey_expired, requests from an IP address that is not allowed fail with kas_apikey_ip_not_allowed.
<?php
$parameters = [];
try {
$client = new SoapClient('https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl');
$response = $client->KasApi(json_encode([
'kas_login' => 'w0123456', // KAS login or subaccount login
'kas_auth_type' => 'apikey', // API key authentication
'kas_auth_data' => $apiKey, // API key (kas_...)
'kas_action' => 'get_domains', // API function
'KasRequestParams' => $parameters, // function parameters
]));
} catch (SoapFault $fault) {
echo "Error code: {$fault->faultcode}\n";
echo "Message: {$fault->faultstring}\n";
}