PHP code example of automattic / domain-services-client

1. Go to this page and download the library: Download automattic/domain-services-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/ */

    

automattic / domain-services-client example snippets




// Change the path as necessary
\{Api, Command, Configuration, Entity, Response};

// Set the domain to use
$domain_name = new Entity\Domain_Name( 'a8ctest.com' );

// Set up a new domain contact
$domain_contacts = new Entity\Domain_Contacts(
	new Entity\Domain_Contact(
		new Entity\Contact_Information(
			'John',
			'Doe',
			'',
			'123 Main St',
			'',
			'23601',
			'Utopia',
			'ST',
			'CC',
			'[email protected]',
			'+1.7575551234',
			''
		)
	)
);

// Set up the Contacts\Set command
$command = new Command\Domain\Set\Contacts( $domain_name, $domain_contacts );

// Create an optional client transaction ID (useful for finding related log entries)
$client_transaction_id = 'client_tx_id_example';

// Configure API key authorization: apiKey
$config = Configuration::get_default_configuration()
    ->set_api_key( 'X-DSAPI-KEY', 'your-key-here' )
    ->set_api_key( 'X-DSAPI-USER', 'your-user-here' );

// Using Guzzle 7
$http_client = new GuzzleHttp\Client();
$http_factory = new GuzzleHttp\Psr7\HttpFactory();

$request_factory = new Request\Factory( $http_factory, $http_factory );
$response_factory = new Response\Factory();

$api = new Api( $config, $request_factory, $response_factory, $http_client );

try {
	// Make the call to the endpoint
	/** @var Response\Domain\Set\Contacts $response */
	$response = $api->post( $command, $client_transaction_id );

	// Extract some data from the resopnse
	echo "Status: " . $response->get_status() . "\n";
	echo "Status description: " . $response->get_status_description() . "\n";
	echo "New contact ID: " . $response->get_contacts()->get_owner()->get_contact_id()->get_provider_contact_id() . "\n";
} catch (Exception $e) {
	echo 'Exception when calling Domain_Set_Contacts: ', $e->getMessage(), PHP_EOL;
}