PHP code example of tiggee / constellix-v4-client

1. Go to this page and download the library: Download tiggee/constellix-v4-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tiggee / constellix-v4-client example snippets



$httpClient = new \GuzzleHttp\Client();

$client = new \Constellix\Client\Client($httpClient);
$client->setApiKey(API_KEY);
$client->setSecretKey(SECRET_KEY);


// Load the library and dependencies
als
$httpClient = new \GuzzleHttp\Client();
$client = new \Constellix\Client\Client($client);
$client->setApiKey("Your API Key");
$client->setSecretKey("Your Secret Key");


// Create a new domain
$domain = $client->domains->create();
$domain->name = 'mydomain.example.com';
$domain->save();

// Print out our domain
echo json_encode($domain, JSON_PRETTY_PRINT);

// Now fetch a list of our domains
$domains = $client->domains->paginate();
foreach ($domains as $domain) {
    echo json_encode($domain, JSON_PRETTY_PRINT);
}

$myLogger = new \Monolog\Logger('name');
$myLogger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Psr\Log\LogLevel::DEBUG));

$client = new \Constellix\Client\Client(logger: $myLogger);

$myLogger = new \Monolog\Logger('name');
$myLogger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Psr\Log\LogLevel::DEBUG));

$client->setLogger($myLogger);

$myClient = new \GuzzleHttp\Client([
    'proxy' => 'http://localhost:8123'
]);
$client = new \Constellix\Client\Client(client: $myClient);

$myClient = new \GuzzleHttp\Client([
    'proxy' => 'http://localhost:8123'
]);
$client->setHttpClient($myClient);

// Fetch our manager
$domainsManager = $client->domains;
// Ask our manager for the domain
$domain = $domainsManager->get(1234);

// Create a new domain
$domain = $client->domains->create();
$domain->name = 'example.com';

// Save the domain
$domain->save();

// Return the 4th page of results with the default page size
$client->domains->paginate(4);

// Return the first page of 50 results
$client->domains->paginate(1, 50);

// Fetch an existing domain with the ID 1234
$domain = $client->domains->get(1234);
// Update the gtdEnabled property
$domain->gtdEnabled = true;
// Save the domain object on the API
$domain->save();

$domain = $client->domains->get(1234);
$domain->delete();

// Include composer libraries
 = new \Constellix\Client\Client;
$client->setApiKey(API_KEY);
$client->setSecretKey(SECRET_KEY);

// Create the domain
$domain = $client->domains->create();
$domain->name = 'example.com';
$domain->save();

// Create a record on the domain
$record = $domain->records->create();
$record->type = \Constellix\Client\Enums\RecordType::A();
$record->name = 'www';

// Create a value for the record and assign it to the record
$value = new \Constellix\Client\Models\Helpers\RecordValues\Standard();
$value->value = '192.0.2.1';
$record->value = $value;

// Save the record
$record->save();

// Get a list of all domains
$domains = $client->domains->paginate();
foreach ($domains as $domain) {
    print_r(json_encode($domain, JSON_PRETTY_PRINT));
}

$domain = $client->domains->get(1234);
$record = $domain->records->create();
$record->type = \Constellix\Client\Enums\RecordType::A();
$record->name = 'www';

// Create some values
$newValue1 = new \Constellix\Client\Models\Helpers\RecordValues\Standard();
$newValue1->value = '192.0.2.1';

$newValue2 = new \Constellix\Client\Models\Helpers\RecordValues\Standard();
$newValue2->value = '192.0.2.2';

// Assign an array to the value property
$record->value = [
    $newValue1,
    $newValue2,
];

// Add a new value using the addValue() method
$newValue3 = new \Constellix\Client\Models\Helpers\RecordValues\Standard();
$newValue3->value = '192.0.2.3';

$record->addValue($newValue3);

// Save the record to persist these changes
$record->save();

$client->domains->paginate(filters: ['name' => '*example.com']);