30, 'connect_timeout' => 5, ]); // Create a new attached domain $conn = new Api( $applicationKey, $applicationSecret, $endpoint, $consumer_key, $http_client); try { // This call will create a "task". The task is the status of the attached domain creation. // You can follow the task on /hosting/web/{serviceName}/tasks/{id} $task = $conn->post('/hosting/web/' . $domain . '/attachedDomain', array( 'domain' => $domainToAttach, 'path' => $path, 'cdn' => $cdn, 'firewall' => $firewall, 'ownLog' => $ownLog, )); echo "Task #" . $task['id'] . " is created" . PHP_EOL; // we check every 5 seconds if the task is done // When the task disappears, the task is done while ( 1 ) { try { $wait = $conn->get('/hosting/web/' . $domain . '/tasks/' . $task['id']); if ( strcmp( $wait['status'], 'error' ) === 0 ) { // The task is in error state. Please check your parameters, retry or contact support. echo "An error has occured during the task" . PHP_EOL; break; } elseif ( strcmp( $wait['status'], 'cancelled' ) === 0 ) { // The task is in cancelled state. Please check your parameters, retry or contact support. echo "Task has been cancelled during the task" . PHP_EOL; break; } echo "Status of task #". $wait['id'] . " is '". $wait['status'] ."'" . PHP_EOL; } catch ( \GuzzleHttp\Exception\ClientException $ex) { $response = $ex->getResponse(); if ( $response && $response->getStatusCode() === 404 ) { echo "Domain attached to the web hosting" . PHP_EOL; break; } throw $ex; } sleep(5); } } catch ( Exception $ex ) { print_r( $ex->getMessage() ); } ?>