get('/domain/zone/' . $domain . '/record?subDomain='. $subDomain ); // If subdomain is not defined, we don't want to delete all A, AAAA and CNAME records if ( isset($subDomain) ) { foreach ($recordIds as $recordId) { $record = $conn->get('/domain/zone/' . $domain . '/record/' . $recordId); // If record include A, AAAA or CNAME for subdomain asked, we delete it if ( in_array( $record['fieldType'], array( 'A', 'AAAA', 'CNAME' ) ) ) { echo "We will delete field " . $record['fieldType'] . " for " . $record['subDomain'] . $record['zone'] . PHP_EOL; $conn->delete('/domain/zone/' . $domain . '/record/' . $recordId); } } } // Now, we are ready to create our new redirection $redirection = $conn->post('/domain/zone/' . $domain . '/redirection', array( 'subDomain' => $subDomain, 'target' => $targetDomain, 'type' => $type, 'title' => $title, 'description' => $description, 'keywords' => $keywords, )); // We apply zone changes $conn->post('/domain/zone/' . $domain . '/refresh'); print_r( $redirection ); } catch ( Exception $ex ) { print_r( $ex->getMessage() ); } ?>