Example #1
0
 /**
  * Test if delete request on /me
  */
 public function testDeleteRestrictionAccessIP()
 {
     $result = $this->api->get('/me/accessRestriction/ip');
     foreach ($result as $restrictionId) {
         $restriction = $this->api->get('/me/accessRestriction/ip/' . $restrictionId);
         if (in_array($restriction["ip"], [$this->rangeIP, $this->alternativeRangeIP])) {
             $result = $this->api->delete('/me/accessRestriction/ip/' . $restrictionId);
             $this->assertNull($result);
             break;
         }
     }
 }
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumer_key = "your_consumer_key";
// Information about API and rights asked
$endpoint = 'ovh-eu';
// Informations about your web hosting and the attached domain (compulsory)
$domain = 'mydomain.ovh';
// Web hosting id (often domain order with it)
$domainToAttach = 'myotherdomaintoattach.ovh';
$http_client = new Client(['timeout' => 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 deletion.
    // You can follow the task on /hosting/web/{serviceName}/tasks/{id}
    $task = $conn->delete('/hosting/web/' . $domain . '/attachedDomain/' . $domainToDetach);
    echo "Task #" . $task['id'] . " is created" . PHP_EOL;
    // we check every 5 seconds if 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;
            }
Example #3
0
$targetDomain = 'my_target.ovh';
$type = 'visible';
// can be "visible", "invisible", "visiblePermanent"
// Field to set in case of invisible redirection
$title = '';
$keywords = '';
$description = '';
// Get servers list
$conn = new Api($applicationKey, $applicationSecret, $endpoint, $consumer_key);
try {
    // check if dns record are available
    $recordIds = $conn->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());
}